From: Good Guy Date: Sat, 16 May 2020 22:14:53 +0000 (-0600) Subject: fix valgrind memory leaks/reports, add cache to dump, fix hw probe frame leak, startu... X-Git-Tag: 2020-05~5 X-Git-Url: https://cinelerra-gg.org/git/?a=commitdiff_plain;h=3643286e2dbb3002604a62e3e6fd834716b4ae63;p=goodguy%2Fcinelerra.git fix valgrind memory leaks/reports, add cache to dump, fix hw probe frame leak, startup lock for lv2 plugins --- diff --git a/cinelerra-5.1/cinelerra/cache.C b/cinelerra-5.1/cinelerra/cache.C index 63bb4a0d..b8e2326d 100644 --- a/cinelerra-5.1/cinelerra/cache.C +++ b/cinelerra-5.1/cinelerra/cache.C @@ -273,16 +273,16 @@ int CICache::delete_oldest() return result; } -void CICache::dump() +void CICache::dump(FILE *fp) { CICacheItem *current; total_lock->lock("CICache::dump"); - printf("CICache::dump total size %jd\n", get_memory_usage(0)); + fprintf(fp, "CICache::dump total size %jd\n", get_memory_usage(0)); for(current = first; current; current = NEXT) { - printf("cache item %p asset %p %s age=%d\n", - current, current->asset, - current->asset->path, current->age); + fprintf(fp, "cache item %p asset %p %s age=%d checked_out=%p\n", + current, current->asset, current->asset->path, + current->age, (void*)current->checked_out); } total_lock->unlock(); } diff --git a/cinelerra-5.1/cinelerra/cache.h b/cinelerra-5.1/cinelerra/cache.h index fde997a5..8ab4457f 100644 --- a/cinelerra-5.1/cinelerra/cache.h +++ b/cinelerra-5.1/cinelerra/cache.h @@ -104,10 +104,7 @@ public: // deletes oldest assets until under the memory limit int age(); - - void dump(); - - + void dump(FILE *fp); private: // for deleting items diff --git a/cinelerra-5.1/cinelerra/edl.C b/cinelerra-5.1/cinelerra/edl.C index 6739dec8..130f80bb 100644 --- a/cinelerra-5.1/cinelerra/edl.C +++ b/cinelerra-5.1/cinelerra/edl.C @@ -2278,6 +2278,8 @@ int EDL::collect_effects(EDL *&group) } if( !ret ) group = new_edl; + else + new_edl->remove_user(); return ret; } diff --git a/cinelerra-5.1/cinelerra/ffmpeg.C b/cinelerra-5.1/cinelerra/ffmpeg.C index 58d280c0..493be6ab 100644 --- a/cinelerra-5.1/cinelerra/ffmpeg.C +++ b/cinelerra-5.1/cinelerra/ffmpeg.C @@ -428,14 +428,14 @@ int FFStream::decode_activate() avctx->thread_count = ffmpeg->ff_cpus(); ret = avcodec_open2(avctx, decoder, &copts); } + AVFrame *hw_frame = 0; if( ret >= 0 && hw_type != AV_HWDEVICE_TYPE_NONE ) { - AVFrame *frame = av_frame_alloc(); - if( !frame ) { + if( !(hw_frame=av_frame_alloc()) ) { fprintf(stderr, "FFStream::decode_activate: av_frame_alloc failed\n"); ret = AVERROR(ENOMEM); } if( ret >= 0 ) - ret = decode(frame); + ret = decode(hw_frame); } if( ret < 0 && hw_type != AV_HWDEVICE_TYPE_NONE ) { ff_err(ret, "HW device init failed, using SW decode.\nfile:%s\n", @@ -444,7 +444,7 @@ int FFStream::decode_activate() avcodec_free_context(&avctx); av_buffer_unref(&hw_device_ctx); hw_device_ctx = 0; - av_frame_free(&frame); + av_frame_free(&hw_frame); hw_type = AV_HWDEVICE_TYPE_NONE; int flags = AVSEEK_FLAG_BACKWARD | AVSEEK_FLAG_ANY; int idx = st->index; @@ -454,7 +454,7 @@ int FFStream::decode_activate() ret = 0; continue; } - probe_frame = frame; + probe_frame = hw_frame; if( ret >= 0 ) reading = 1; else diff --git a/cinelerra-5.1/cinelerra/mwindow.C b/cinelerra-5.1/cinelerra/mwindow.C index 8b93262c..b38e3c65 100644 --- a/cinelerra-5.1/cinelerra/mwindow.C +++ b/cinelerra-5.1/cinelerra/mwindow.C @@ -4642,6 +4642,14 @@ void MWindow::dump_exe(FILE *fp) fprintf(fp, "\n"); } +void MWindow::dump_caches(FILE *fp) +{ + fprintf(fp, "audio cache: "); + audio_cache->dump(fp); + fprintf(fp, "video cache: "); + video_cache->dump(fp); +} + void MWindow::trap_hook(FILE *fp, void *vp) { MWindow *mwindow = (MWindow *)vp; @@ -4653,6 +4661,8 @@ void MWindow::trap_hook(FILE *fp, void *vp) mwindow->dump_undo(fp); fprintf(fp, "\nEXE: %s\n", AboutPrefs::build_timestamp); mwindow->dump_exe(fp); + fprintf(fp, "\nCACHES:\n"); + mwindow->dump_caches(fp); } diff --git a/cinelerra-5.1/cinelerra/mwindow.h b/cinelerra-5.1/cinelerra/mwindow.h index 826ca600..c94a7bd5 100644 --- a/cinelerra-5.1/cinelerra/mwindow.h +++ b/cinelerra-5.1/cinelerra/mwindow.h @@ -598,6 +598,7 @@ public: void dump_edl(FILE *fp=stdout); void dump_undo(FILE *fp=stdout); void dump_exe(FILE *fp=stdout); + void dump_caches(FILE *fp=stdout); static void trap_hook(FILE *fp, void *vp); void reset_android_remote(); diff --git a/cinelerra-5.1/cinelerra/performanceprefs.h b/cinelerra-5.1/cinelerra/performanceprefs.h index 3e00f9d8..e9acd3c7 100644 --- a/cinelerra-5.1/cinelerra/performanceprefs.h +++ b/cinelerra-5.1/cinelerra/performanceprefs.h @@ -338,6 +338,13 @@ public: PreferencesWindow *pwindow; }; +class PrefsUseHWDevItems : public ArrayList +{ +public: + PrefsUseHWDevItems() {} + ~PrefsUseHWDevItems() { remove_all_objects(); } +}; + class PrefsUseHWDev : public BC_PopupTextBox { public: @@ -347,7 +354,7 @@ public: int handle_event(); PreferencesWindow *pwindow; - ArrayList hw_dev_names; + PrefsUseHWDevItems hw_dev_names; }; diff --git a/cinelerra-5.1/cinelerra/pluginlv2.C b/cinelerra-5.1/cinelerra/pluginlv2.C index 7b7dc678..c6ef09cb 100644 --- a/cinelerra-5.1/cinelerra/pluginlv2.C +++ b/cinelerra-5.1/cinelerra/pluginlv2.C @@ -52,6 +52,8 @@ PluginLV2::PluginLV2() schedule.schedule_work = lv2_worker_schedule; worker_iface = 0; worker_done = -1; pthread_mutex_init(&worker_lock, 0); + pthread_mutex_init(&startup_lock, 0); + pthread_mutex_lock(&startup_lock); pthread_cond_init(&worker_ready, 0); work_avail = 0; work_input = 0; work_output = 0; work_tail = &work_output; @@ -417,6 +419,7 @@ PluginLV2Work *PluginLV2::get_work() void *PluginLV2::worker_func() { pthread_mutex_lock(&worker_lock); + pthread_mutex_unlock(&startup_lock); for(;;) { while( !worker_done && !work_input ) pthread_cond_wait(&worker_ready, &worker_lock); @@ -440,6 +443,7 @@ void *PluginLV2::worker_func(void* vp) void PluginLV2::worker_start() { pthread_create(&worker_thread, 0, worker_func, this); + pthread_mutex_lock(&startup_lock); } void PluginLV2::worker_stop() diff --git a/cinelerra-5.1/cinelerra/pluginlv2.h b/cinelerra-5.1/cinelerra/pluginlv2.h index ac99d253..6f1e6009 100644 --- a/cinelerra-5.1/cinelerra/pluginlv2.h +++ b/cinelerra-5.1/cinelerra/pluginlv2.h @@ -137,7 +137,7 @@ public: LV2_Worker_Schedule schedule; PluginLV2Work *work_avail, *work_input; PluginLV2Work *work_output, **work_tail; - pthread_mutex_t worker_lock; + pthread_mutex_t startup_lock, worker_lock; pthread_cond_t worker_ready; int worker_done; }; diff --git a/cinelerra-5.1/guicast/bcresources.C b/cinelerra-5.1/guicast/bcresources.C index 1d528559..2fb8f4f8 100644 --- a/cinelerra-5.1/guicast/bcresources.C +++ b/cinelerra-5.1/guicast/bcresources.C @@ -1856,7 +1856,7 @@ void BC_Resources::encode_to_utf8(char *buffer, int buflen) { if(BC_Resources::locale_utf8) return; char lbuf[buflen]; - encode(encoding, 0, buffer, buflen, lbuf, buflen); + encode(encoding, 0, buffer, -1, lbuf, buflen); strcpy(buffer, lbuf); }