fix valgrind memory leaks/reports, add cache to dump, fix hw probe frame leak, startu... master
authorGood Guy <good1.2guy@gmail.com>
Sat, 16 May 2020 22:14:53 +0000 (16:14 -0600)
committerGood Guy <good1.2guy@gmail.com>
Sat, 16 May 2020 22:14:53 +0000 (16:14 -0600)
cinelerra-5.1/cinelerra/cache.C
cinelerra-5.1/cinelerra/cache.h
cinelerra-5.1/cinelerra/edl.C
cinelerra-5.1/cinelerra/ffmpeg.C
cinelerra-5.1/cinelerra/mwindow.C
cinelerra-5.1/cinelerra/mwindow.h
cinelerra-5.1/cinelerra/performanceprefs.h
cinelerra-5.1/cinelerra/pluginlv2.C
cinelerra-5.1/cinelerra/pluginlv2.h
cinelerra-5.1/guicast/bcresources.C

index 63bb4a0de4b32e9e5b9dcb0480c4f751c0f933c2..b8e2326dbc823d01aff508590875f8fb0ff420b3 100644 (file)
@@ -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();
 }
index fde997a50289c41ee76f725681d6d2ad12eddc94..8ab4457f982ad370ae1bd3d3431260b921533572 100644 (file)
@@ -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
index 6739dec89dab284da8dec9be63a6128e5e6fe0c0..130f80bb97c4557b1a26ff1b8587d0db21ef0e72 100644 (file)
@@ -2278,6 +2278,8 @@ int EDL::collect_effects(EDL *&group)
        }
        if( !ret )
                group = new_edl;
+       else
+               new_edl->remove_user();
        return ret;
 }
 
index 58d280c00edf60315dd93d383e05196d9ee04a49..493be6abeace4e55e9eac4177964649a63c6fc2e 100644 (file)
@@ -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
index 8b93262c4e6930cd53027d40c9b3b5f2309d1c67..b38e3c653c57556ac36f90595162b1100861c01f 100644 (file)
@@ -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);
 }
 
 
index 826ca600abb693afc81a294323ec94b4273051b2..c94a7bd52dc77d08f7746fea59808ecf8d972989 100644 (file)
@@ -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();
index 3e00f9d8e828cb6269441d7865e29033f9ccf1db..e9acd3c70f8c9212170ec900c36ceb078209ee3f 100644 (file)
@@ -338,6 +338,13 @@ public:
        PreferencesWindow *pwindow;
 };
 
+class PrefsUseHWDevItems : public ArrayList<BC_ListBoxItem *>
+{
+public:
+       PrefsUseHWDevItems() {}
+       ~PrefsUseHWDevItems() { remove_all_objects(); }
+};
+
 class PrefsUseHWDev : public BC_PopupTextBox
 {
 public:
@@ -347,7 +354,7 @@ public:
        int handle_event();
 
        PreferencesWindow *pwindow;
-       ArrayList<BC_ListBoxItem *> hw_dev_names;
+       PrefsUseHWDevItems hw_dev_names;
 };
 
 
index 7b7dc678e717b2dd1578bfb3f4f3cad2092852e4..c6ef09cbe2125257a6dc07c004b9402f11b750fd 100644 (file)
@@ -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()
index ac99d2535dfc3015ba23ba910db6b28f8016ba53..6f1e60096a94cbbbad1df6b8d84ab78394c18859 100644 (file)
@@ -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;
 };
index 1d52855990ee9e7e5a10eb32f518e446e98d3087..2fb8f4f8b200aaeeff7fd47e256e07d0e3d201f4 100644 (file)
@@ -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);
 }