fixup a bunch of memory use issues
authorGood Guy <good1.2guy@gmail.com>
Fri, 1 Jan 2016 22:43:45 +0000 (15:43 -0700)
committerGood Guy <good1.2guy@gmail.com>
Fri, 1 Jan 2016 22:43:45 +0000 (15:43 -0700)
15 files changed:
cinelerra-5.0/cinelerra/awindowgui.C
cinelerra-5.0/cinelerra/mwindow.C
cinelerra-5.0/cinelerra/pluginfclient.C
cinelerra-5.0/cinelerra/pluginserver.C
cinelerra-5.0/cinelerra/pluginserver.h
cinelerra-5.0/cinelerra/theme.C
cinelerra-5.0/guicast/bcsynchronous.C
cinelerra-5.0/guicast/bcwindowbase.C
cinelerra-5.0/plugins/blondtheme/blondtheme.C
cinelerra-5.0/plugins/bluedottheme/bluedottheme.C
cinelerra-5.0/plugins/brighttheme/brighttheme.C
cinelerra-5.0/plugins/defaulttheme/defaulttheme.C
cinelerra-5.0/plugins/microtheme/microtheme.C
cinelerra-5.0/plugins/suv/suv.C
cinelerra-5.0/plugins/titler/title.C

index 3e4c383b9f5095abe32d6a829220dc8aa2e772b1..3052201f1cdf36c54628f6bcdd5f8ec087a70883 100644 (file)
@@ -772,7 +772,7 @@ void AWindowRemovePlugin::handle_close_event(int result)
                MWindow *mwindow = awindow->mwindow;
                sprintf(index_path, "%s/%s", mwindow->preferences->plugin_dir, PLUGIN_FILE);
                mwindow->plugindb->remove(plugin);
-               plugin->delete_this();
+               delete plugin;  plugin = 0;
                remove(plugin_path);
                if( png_path[0] ) remove(png_path);
                remove(index_path);
index 18488f84685bb66ff3b521306229639cd6a43315..27a6d76bc85dcf561cb492cbe80d6648b6c536da 100644 (file)
@@ -279,7 +279,6 @@ MWindow::~MWindow()
        join();
 #endif
        reset_caches();
-       delete_plugins();
        dead_plugins->remove_all();
        finit_error();
        keyframe_threads->remove_all_objects();
@@ -311,6 +310,7 @@ MWindow::~MWindow()
        delete assets;          assets = 0;
        delete splash_window;   splash_window = 0;
        delete theme;           theme = 0;
+       delete_plugins();
        delete channeldb_buz;
        delete channeldb_v4l2jpeg;
 // This must be last thread to exit
@@ -446,24 +446,22 @@ void MWindow::init_plugin_index(MWindow *mwindow, Preferences *preferences, FILE
                        continue;
                }
                if( plugin_exists(plugin_path) ) continue;
-               PluginServer *server = new PluginServer(mwindow, plugin_path, PLUGIN_TYPE_UNKNOWN);
-               result = server->open_plugin(1, preferences, 0, 0);
+               PluginServer server(mwindow, plugin_path, PLUGIN_TYPE_UNKNOWN);
+               result = server.open_plugin(1, preferences, 0, 0);
                if( !result ) {
-                       server->write_table(fp,vis_id);
-                       server->close_plugin();
-                       server->delete_this();
-                       continue;
+                       server.write_table(fp,vis_id);
+                       server.close_plugin();
                }
-               if( result != PLUGINSERVER_IS_LAD ) continue;
-               int lad_index = 0;
-               for(;;) {
-                       PluginServer *server = new PluginServer(mwindow, plugin_path, PLUGIN_TYPE_LADSPA);
-                       server->set_lad_index(lad_index++);
-                       result = server->open_plugin(1, preferences, 0, 0);
-                       if( result ) break;
-                       server->write_table(fp, PLUGIN_LADSPA_ID);
-                       server->close_plugin();
-                       server->delete_this();
+               else if( result == PLUGINSERVER_IS_LAD ) {
+                       int lad_index = 0;
+                       for(;;) {
+                               PluginServer ladspa(mwindow, plugin_path, PLUGIN_TYPE_LADSPA);
+                               ladspa.set_lad_index(lad_index++);
+                               result = ladspa.open_plugin(1, preferences, 0, 0);
+                               if( result ) break;
+                               ladspa.write_table(fp, PLUGIN_LADSPA_ID);
+                               ladspa.close_plugin();
+                       }
                }
        }
 }
@@ -723,17 +721,17 @@ void MWindow::init_theme()
                exit(1);
        }
 
-       PluginServer plugin = *theme_plugin;
-       if( plugin.open_plugin(0, preferences, 0, 0) ) {
+       PluginServer *plugin = new PluginServer(*theme_plugin);
+       if( plugin->open_plugin(0, preferences, 0, 0) ) {
                fprintf(stderr, _("MWindow::init_theme: unable to load theme %s\n"),
                        theme_plugin->title);
                exit(1);
        }
 
-       theme = plugin.new_theme();
+       theme = plugin->new_theme();
        theme->mwindow = this;
-       strcpy(theme->path, plugin.path);
-       plugin.close_plugin();
+       strcpy(theme->path, plugin->path);
+       delete plugin;
 
 // Load default images & settings
        theme->Theme::initialize();
index d57bcb9a7c39ee466672f1e0f6c8798082c067b3..bb483e2cd358313c6d6cfca64dcf7e9711688bb4 100644 (file)
@@ -1136,7 +1136,7 @@ void MWindow::init_ffmpeg_index(MWindow *mwindow, Preferences *preferences, FILE
                                server->write_table(fp, PLUGIN_FFMPEG_ID);
                                server->close_plugin();
                        }
-                       server->delete_this();
+                       delete server;
                        if( result ) fprintf(fp, "#%s\n", filter->name);
                }
        }
index cd7ca1f4bb703f43c0689d3bcf4573f8afb5d4be..609710276599b8cb0de1439e9db02ab810f670ff 100644 (file)
@@ -74,6 +74,7 @@ void PluginServer::init()
 {
        reset_parameters();
        this->plugin_type = PLUGIN_TYPE_UNKNOWN;
+       plugin_obj = new PluginObj();
        modules = new ArrayList<Module*>;
        nodes = new ArrayList<VirtualNode*>;
 }
@@ -101,6 +102,8 @@ PluginServer::PluginServer(PluginServer &that)
 {
        reset_parameters();
        plugin_type = that.plugin_type;
+       plugin_obj = that.plugin_obj;
+       plugin_obj->add_user();
        title = !that.title ? 0 : cstrdup(that.title);
        path = !that.path ? 0 : cstrdup(that.path);
        ff_name = !that.ff_name ? 0 : cstrdup(that.ff_name);
@@ -135,6 +138,7 @@ PluginServer::~PluginServer()
        delete modules;
        delete nodes;
        delete picon;
+       plugin_obj->remove_user();
 }
 
 // Done only once at creation
@@ -146,7 +150,6 @@ int PluginServer::reset_parameters()
        cleanup_plugin();
        autos = 0;
        edl = 0;
-       dlobj = 0;
        preferences = 0;
        title = 0;
        path = 0;
@@ -265,34 +268,36 @@ void PluginServer::generate_display_title(char *string)
                strcpy(string, ltitle);
 }
 
-void *PluginServer::load_obj()
+void *PluginObj::load(const char *plugin_dir, const char *path)
 {
-       if( !dlobj ) {
-               char dlpath[BCTEXTLEN], *dp = dlpath;
-               char *cp = path;
-               if( *cp != '/' ) {
-                       char *bp = preferences->plugin_dir;
-                       while( *bp ) *dp++ = *bp++;
-                       *dp++ = '/';
-               }
-               while( *cp ) *dp++ = *cp++;
-               *dp = 0;
-               dlobj = load(dlpath);
+       char dlpath[BCTEXTLEN], *dp = dlpath;
+       const char *cp = path;
+       if( *cp != '/' ) {
+               const char *bp = plugin_dir;
+               while( *bp ) *dp++ = *bp++;
+               *dp++ = '/';
        }
-       return dlobj;
+       while( *cp ) *dp++ = *cp++;
+       *dp = 0;
+       return dlobj = load(dlpath);
 }
 
-void PluginServer::unload_obj()
+int PluginServer::load_obj()
 {
-       if( !dlobj ) return;
-       unload(dlobj);  dlobj = 0;
+       void *obj = plugin_obj->obj();
+       if( !obj ) obj =plugin_obj->load(preferences->plugin_dir, path);
+       return obj ? 1 : 0;
 }
 
-void PluginServer::delete_this()
+const char *PluginServer::load_error()
 {
-       void *obj = dlobj;
-       delete this;
-       if( obj ) unload(obj);
+       return plugin_obj->load_error();
+}
+
+void *PluginServer::get_sym(const char *sym)
+{
+       if( !plugin_obj->obj() ) return 0;
+       return plugin_obj->load_sym(sym);
 }
 
 // Open plugin for signal processing
@@ -313,25 +318,22 @@ int PluginServer::open_plugin(int master,
                char string[BCTEXTLEN];
                strcpy(string, load_error());
                if( !strstr(string, "executable") ) {
-                       eprintf("PluginServer::open_plugin: load_obj failure = %s\n", string);
+                       eprintf("PluginServer::open_plugin: load_obj %s = %s\n", path, string);
                        return PLUGINSERVER_NOT_RECOGNIZED;
                }
                plugin_type = PLUGIN_TYPE_EXECUTABLE;
        }
        if( plugin_type == PLUGIN_TYPE_UNKNOWN || plugin_type == PLUGIN_TYPE_BUILTIN ) {
                new_plugin =
-                       (PluginClient* (*)(PluginServer*)) load_sym("new_plugin");
+                       (PluginClient* (*)(PluginServer*)) get_sym("new_plugin");
                if( new_plugin )
                        plugin_type = PLUGIN_TYPE_BUILTIN;
        }
        if( plugin_type == PLUGIN_TYPE_UNKNOWN || plugin_type == PLUGIN_TYPE_LADSPA ) {
                lad_descriptor_function =
-                       (LADSPA_Descriptor_Function) load_sym("ladspa_descriptor");
+                       (LADSPA_Descriptor_Function) get_sym("ladspa_descriptor");
                if( lad_descriptor_function ) {
-                       if( lad_index < 0 ) {
-                               unload_obj();
-                               return PLUGINSERVER_IS_LAD;
-                       }
+                       if( lad_index < 0 ) return PLUGINSERVER_IS_LAD;
                        lad_descriptor = lad_descriptor_function(lad_index);
                        if( !lad_descriptor )
                                return PLUGINSERVER_NOT_RECOGNIZED;
@@ -341,7 +343,6 @@ int PluginServer::open_plugin(int master,
        if( plugin_type == PLUGIN_TYPE_UNKNOWN ) {
                fprintf(stderr, "PluginServer::open_plugin "
                        " %d: plugin undefined in %s\n", __LINE__, path);
-               unload_obj();
                return PLUGINSERVER_NOT_RECOGNIZED;
        }
        switch( plugin_type ) {
@@ -443,8 +444,8 @@ int PluginServer::read_table(char *text)
                &plugin_type, path, title, &dir_idx, &audio, &video, &theme, &realtime,
                &fileio, &uses_gui, &multichannel, &synthesis, &transition, &lad_index);
        if( n != 14 ) return 1;
-       this->path = cstrdup(path);
-       this->title = cstrdup(title);
+       set_path(path);
+       set_title(title);
        return 0;
 }
 
index e174ebaa9ae24e464cbc009c16a72de9374421da..86a394d65cc4a32a6f705629799a76b11cdfbfde 100644 (file)
@@ -35,6 +35,7 @@
 #include "edl.inc"
 #include "floatauto.inc"
 #include "floatautos.inc"
+#include "garbage.h"
 #include "keyframe.inc"
 #include "ladspa.h"
 #include "mainprogress.inc"
 
 #include <dlfcn.h>
 
-class PluginServer
-{
-       int reset_parameters();
-       void init();
-       int cleanup_plugin();
-
+class PluginObj : public Garbage {
        void *dlobj;
+public:
+
        void *load(const char *dlp) { return dlobj = dlopen(dlp, RTLD_NOW); }
+       void *load(const char *plugin_dir, const char *path);
        void unload(void *obj) { dlclose(obj); }
        void *load_sym(const char *sym) { return dlsym(dlobj, sym); }
        const char *load_error() { return dlerror(); }
-       void *load_obj();
-       void unload_obj();
+       void *obj() { return dlobj; }
+
+       PluginObj() : Garbage("PluginObj:Garbage") { dlobj = 0; }
+       ~PluginObj() { if( dlobj ) unload(dlobj); }
+};
+
+class PluginServer
+{
+       PluginObj *plugin_obj;
+       int load_obj();
+       const char *load_error();
+       void *get_sym(const char *sym);
+
+       int reset_parameters();
+       void init();
+       int cleanup_plugin();
 
 // Base class created by client
        PluginClient *client;
@@ -112,7 +125,6 @@ public:
                        EDL *edl, Plugin *plugin);
 // close the plugin
        int close_plugin();    
-       void delete_this();
        char *get_plugin_png_path(char *png_path);
        void dump(FILE *fp=stdout);
 // Release any objects which are required after playback stops.
index 549dd11c3bc2f441b07231f30f50c947f568124f..fe869cd74cae730a762bbcd48295ea556c196609 100644 (file)
@@ -102,9 +102,72 @@ Theme::Theme()
        pane_color = BLACK;
        drag_pane_color = WHITE;
 
-       
-
-
+       appendasset_data = 0;
+       append_data = 0;
+       asset_append_data = 0;
+       asset_disk_data = 0;
+       asset_index_data = 0;
+       asset_info_data = 0;
+       asset_project_data = 0;
+       browse_data = 0;
+       calibrate_data = 0;
+       camerakeyframe_data = 0;
+       cancel_data = 0;
+       chain_data = 0;
+       channel_bg_data = 0;
+       channel_position_data = 0;
+       delete_all_indexes_data = 0;
+       deletebin_data = 0;
+       delete_data = 0;
+       deletedisk_data = 0;
+       deleteproject_data = 0;
+       detach_data = 0;
+       dntriangle_data = 0;
+
+       edit_data = 0;
+       edithandlein_data = 0;
+       edithandleout_data = 0;
+       extract_data = 0;
+       ffmpeg_toggle = 0;
+       infoasset_data = 0;
+       in_point = 0;
+       insert_data = 0;
+       keyframe_data = 0;
+       label_toggle = 0;
+       lift_data = 0;
+       maskkeyframe_data = 0;
+       modekeyframe_data = 0;
+       movedn_data = 0;
+       moveup_data = 0;
+       newbin_data = 0;
+       no_data = 0;
+       options_data = 0;
+       out_point = 0;
+       over_button = 0;
+       overwrite_data = 0;
+       pankeyframe_data = 0;
+       pasteasset_data = 0;
+       paused_data = 0;
+       picture_data = 0;
+       presentation_data = 0;
+       presentation_loop = 0;
+       presentation_stop = 0;
+       projectorkeyframe_data = 0;
+       redrawindex_data = 0;
+       renamebin_data = 0;
+       reset_data = 0;
+       reverse_data = 0;
+       rewind_data = 0;
+       select_data = 0;
+       shbtn_data = 0;
+       splice_data = 0;
+       start_over_data = 0;
+       statusbar_cancel_data = 0;
+       timebar_view_data = 0;
+       transition_data = 0;
+       uptriangle_data = 0;
+       viewasset_data = 0;
+       vtimebar_bg_data = 0;
 }
 
 
@@ -118,6 +181,7 @@ Theme::~Theme()
        frame_sizes.remove_all_objects();
        sample_rates.remove_all_objects();
        zoom_values.remove_all_objects();
+
        delete about_bg;
 }
 
index 671ec0df036733fa9f1b5c1815bb893acca4d438..4459fa363051686b076228c832d08b51f4f67776 100644 (file)
@@ -165,6 +165,7 @@ void BC_Synchronous::quit()
        command_lock->unlock();
        next_command->unlock();
        command->command_done->lock("BC_Synchronous::quit");
+       delete command;
 }
 
 long BC_Synchronous::send_command(BC_SynchronousCommand *command)
@@ -212,7 +213,8 @@ void BC_Synchronous::handle_command_base(BC_SynchronousCommand *command)
        switch(command->command) {
        case BC_SynchronousCommand::QUIT:
                done = 1;
-               break;
+               command->command_done->unlock();
+               return;
 
        case BC_SynchronousCommand::DELETE_WINDOW:
                delete_window_sync(command);
@@ -228,10 +230,10 @@ void BC_Synchronous::handle_command_base(BC_SynchronousCommand *command)
 
        default:
                handle_command(command);
-               break;
+               command->command_done->unlock();
+               return;
        }
-
-       command->command_done->unlock();
+       delete command;
 }
 
 void BC_Synchronous::handle_command(BC_SynchronousCommand *command)
@@ -374,7 +376,6 @@ void BC_Synchronous::delete_window(BC_WindowBase *window)
        command->glx_context = window->glx_win_context;
 
        send_garbage(command);
-       command->command_done->lock("BC_Synchronous::delete_window");
 #endif
 }
 
index 602934b1967aad840bfde338492e0812c1546273..6a1961b24064872c49c3ab5bf972134f0b291152 100644 (file)
@@ -136,19 +136,9 @@ BC_WindowBase::~BC_WindowBase()
        delete pixmap;
 
 #ifdef HAVE_GL
-       if( get_resources()->get_synchronous() && top_level->options & GLX_WINDOW ) {
-               if( !glx_win ) {
-// NVIDIA library threading problem, XCloseDisplay SEGVs without this
-                       sync_lock("BC_WindowBase::~BC_WindowBase:XDestroyWindow");
-                       lock_window("BC_WindowBase::~BC_WindowBase:XDestroyWindow");
-                       glXMakeContextCurrent(top_level->display, 0, 0, 0);
-                       XDestroyWindow(top_level->display, win);
-                       unlock_window();
-                       sync_unlock();
-               }
-               else
-                       get_resources()->get_synchronous()->delete_window(this);
-       }
+       if( get_resources()->get_synchronous() &&
+               (top_level->options & GLX_WINDOW) && glx_win != 0 )
+               get_resources()->get_synchronous()->delete_window(this);
        else
 #endif
                XDestroyWindow(top_level->display, win);
@@ -2274,7 +2264,7 @@ void BC_WindowBase::init_xft()
        if(!(largefont_xft =
                (resources.large_font_xft[0] == '-' ?
                        XftFontOpenXlfd(display, screen, resources.large_font_xft) :
-                       XftFontOpenXlfd(display, screen, resources.large_font_xft))) )
+                       XftFontOpenName(display, screen, resources.large_font_xft))) )
                if(!(largefont_xft =
                        XftFontOpenXlfd(display, screen, resources.large_font_xft2)))
                        largefont_xft = XftFontOpenXlfd(display, screen, "fixed");
index 1eec4db40dfce58810d0588b51ebf64d6b939dfb..47a1758e1da600e03facad2f2d52348918a4959b 100644 (file)
@@ -93,6 +93,14 @@ BlondTheme::BlondTheme()
 
 BlondTheme::~BlondTheme()
 {
+       delete camerakeyframe_data;
+       delete channel_bg_data;
+       delete channel_position_data;
+       delete keyframe_data;
+       delete maskkeyframe_data;
+       delete modekeyframe_data;
+       delete pankeyframe_data;
+       delete projectorkeyframe_data;
 }
 
 void BlondTheme::initialize()
index 4f9086847bc4de2a26d2e61665bffa944349719d..ce0dc0abe62afe2fc93cb0800eaefcd4557380ca 100644 (file)
@@ -96,9 +96,10 @@ BlueDotTheme::BlueDotTheme()
 
 BlueDotTheme::~BlueDotTheme()
 {
+       delete camerakeyframe_data;
+       delete channel_bg_data;
        delete channel_position_data;
        delete keyframe_data;
-       delete camerakeyframe_data;
        delete maskkeyframe_data;
        delete modekeyframe_data;
        delete pankeyframe_data;
@@ -560,9 +561,6 @@ void BlueDotTheme::initialize()
        new_image("new_bg", "new_bg.png");
        new_image("setformat_bg", "setformat_bg2.png");
 
-
-       timebar_view_data = new_image("timebar_view.png");
-
 // x, y of Format dialog box
        setformat_w = 600;
        setformat_h = 560;
index b5d7b50117d05c9ada60d2f9e82dd7343c94c926..851974a81b94d139212471ba6dbcf5301a7428cb 100644 (file)
@@ -93,6 +93,13 @@ BrightTheme::BrightTheme()
 
 BrightTheme::~BrightTheme()
 {
+       delete camerakeyframe_data;
+       delete channel_position_data;
+       delete keyframe_data;
+       delete maskkeyframe_data;
+       delete modekeyframe_data;
+       delete pankeyframe_data;
+       delete projectorkeyframe_data;
 }
 
 void BrightTheme::initialize()
index b57f70d35293e545beb6888c92484462b4121076..67f6377af628baab0270831521c8f6746014beac 100644 (file)
@@ -65,6 +65,14 @@ DefaultThemeMain::DefaultThemeMain(PluginServer *server)
 
 DefaultThemeMain::~DefaultThemeMain()
 {
+       delete camerakeyframe_data;
+       delete channel_bg_data;
+       delete channel_position_data;
+       delete keyframe_data;
+       delete maskkeyframe_data;
+       delete modekeyframe_data;
+       delete pankeyframe_data;
+       delete projectorkeyframe_data;
 }
 
 char* DefaultThemeMain::plugin_title()
index f1b9549309b98ba6c9c12b0b946856d38af319fb..37e70eba492e637675c0783fd92a3ac6d4f0571e 100644 (file)
@@ -46,6 +46,14 @@ MicroThemeMain::MicroThemeMain(PluginServer *server)
 
 MicroThemeMain::~MicroThemeMain()
 {
+       delete camerakeyframe_data;
+       delete channel_bg_data;
+       delete channel_position_data;
+       delete keyframe_data;
+       delete maskkeyframe_data;
+       delete modekeyframe_data;
+       delete pankeyframe_data;
+       delete projectorkeyframe_data;
 }
 
 
index 6937885e29c7b9d2eacb60bfc605f051e310c020..586c4dcd5c42c464ce98ec7923679e9780443285 100644 (file)
@@ -93,9 +93,9 @@ SUV::SUV()
 
 SUV::~SUV()
 {
+       delete camerakeyframe_data;
        delete channel_position_data;
        delete keyframe_data;
-       delete camerakeyframe_data;
        delete maskkeyframe_data;
        delete modekeyframe_data;
        delete pankeyframe_data;
index 3b25e1bf600d676e5b8d526b98947c0c44662cda..8ccdb2a3648bfa19b28afd2cfe45454a463bdde5 100644 (file)
@@ -1203,10 +1203,12 @@ void TitleMain::build_previews(TitleWindow *gui)
                        for(int j = 0; j < len; j++)
                        {
                                FT_ULong c = test_string[j];
-                               check_char_code_path(freetype_library,
-                                       font_entry->path,
-                                       c,
-                                       (char *)new_path);
+// memory leaks here are fatal
+//                             check_char_code_path(freetype_library,
+//                                     font_entry->path,
+//                                     c,
+//                                     (char *)new_path);
+                               strcpy(new_path, font_entry->path);
                                if( !load_freetype_face(freetype_library,
                                        freetype_face, new_path)) {
                                        FT_Set_Pixel_Sizes(freetype_face, text_height, 0);