From 9af59e88f3b08deff2567228e1796189cba44c8c Mon Sep 17 00:00:00 2001 From: Good Guy Date: Fri, 1 Jan 2016 15:43:45 -0700 Subject: [PATCH] fixup a bunch of memory use issues --- cinelerra-5.0/cinelerra/awindowgui.C | 2 +- cinelerra-5.0/cinelerra/mwindow.C | 42 ++++++----- cinelerra-5.0/cinelerra/pluginfclient.C | 2 +- cinelerra-5.0/cinelerra/pluginserver.C | 63 +++++++++-------- cinelerra-5.0/cinelerra/pluginserver.h | 30 +++++--- cinelerra-5.0/cinelerra/theme.C | 70 ++++++++++++++++++- cinelerra-5.0/guicast/bcsynchronous.C | 11 +-- cinelerra-5.0/guicast/bcwindowbase.C | 18 ++--- cinelerra-5.0/plugins/blondtheme/blondtheme.C | 8 +++ .../plugins/bluedottheme/bluedottheme.C | 6 +- .../plugins/brighttheme/brighttheme.C | 7 ++ .../plugins/defaulttheme/defaulttheme.C | 8 +++ cinelerra-5.0/plugins/microtheme/microtheme.C | 8 +++ cinelerra-5.0/plugins/suv/suv.C | 2 +- cinelerra-5.0/plugins/titler/title.C | 10 +-- 15 files changed, 192 insertions(+), 95 deletions(-) diff --git a/cinelerra-5.0/cinelerra/awindowgui.C b/cinelerra-5.0/cinelerra/awindowgui.C index 3e4c383b..3052201f 100644 --- a/cinelerra-5.0/cinelerra/awindowgui.C +++ b/cinelerra-5.0/cinelerra/awindowgui.C @@ -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); diff --git a/cinelerra-5.0/cinelerra/mwindow.C b/cinelerra-5.0/cinelerra/mwindow.C index 18488f84..27a6d76b 100644 --- a/cinelerra-5.0/cinelerra/mwindow.C +++ b/cinelerra-5.0/cinelerra/mwindow.C @@ -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(); diff --git a/cinelerra-5.0/cinelerra/pluginfclient.C b/cinelerra-5.0/cinelerra/pluginfclient.C index d57bcb9a..bb483e2c 100644 --- a/cinelerra-5.0/cinelerra/pluginfclient.C +++ b/cinelerra-5.0/cinelerra/pluginfclient.C @@ -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); } } diff --git a/cinelerra-5.0/cinelerra/pluginserver.C b/cinelerra-5.0/cinelerra/pluginserver.C index cd7ca1f4..60971027 100644 --- a/cinelerra-5.0/cinelerra/pluginserver.C +++ b/cinelerra-5.0/cinelerra/pluginserver.C @@ -74,6 +74,7 @@ void PluginServer::init() { reset_parameters(); this->plugin_type = PLUGIN_TYPE_UNKNOWN; + plugin_obj = new PluginObj(); modules = new ArrayList; nodes = new ArrayList; } @@ -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; } diff --git a/cinelerra-5.0/cinelerra/pluginserver.h b/cinelerra-5.0/cinelerra/pluginserver.h index e174ebaa..86a394d6 100644 --- a/cinelerra-5.0/cinelerra/pluginserver.h +++ b/cinelerra-5.0/cinelerra/pluginserver.h @@ -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" @@ -58,19 +59,31 @@ #include -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. diff --git a/cinelerra-5.0/cinelerra/theme.C b/cinelerra-5.0/cinelerra/theme.C index 549dd11c..fe869cd7 100644 --- a/cinelerra-5.0/cinelerra/theme.C +++ b/cinelerra-5.0/cinelerra/theme.C @@ -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; } diff --git a/cinelerra-5.0/guicast/bcsynchronous.C b/cinelerra-5.0/guicast/bcsynchronous.C index 671ec0df..4459fa36 100644 --- a/cinelerra-5.0/guicast/bcsynchronous.C +++ b/cinelerra-5.0/guicast/bcsynchronous.C @@ -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 } diff --git a/cinelerra-5.0/guicast/bcwindowbase.C b/cinelerra-5.0/guicast/bcwindowbase.C index 602934b1..6a1961b2 100644 --- a/cinelerra-5.0/guicast/bcwindowbase.C +++ b/cinelerra-5.0/guicast/bcwindowbase.C @@ -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"); diff --git a/cinelerra-5.0/plugins/blondtheme/blondtheme.C b/cinelerra-5.0/plugins/blondtheme/blondtheme.C index 1eec4db4..47a1758e 100644 --- a/cinelerra-5.0/plugins/blondtheme/blondtheme.C +++ b/cinelerra-5.0/plugins/blondtheme/blondtheme.C @@ -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() diff --git a/cinelerra-5.0/plugins/bluedottheme/bluedottheme.C b/cinelerra-5.0/plugins/bluedottheme/bluedottheme.C index 4f908684..ce0dc0ab 100644 --- a/cinelerra-5.0/plugins/bluedottheme/bluedottheme.C +++ b/cinelerra-5.0/plugins/bluedottheme/bluedottheme.C @@ -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; diff --git a/cinelerra-5.0/plugins/brighttheme/brighttheme.C b/cinelerra-5.0/plugins/brighttheme/brighttheme.C index b5d7b501..851974a8 100644 --- a/cinelerra-5.0/plugins/brighttheme/brighttheme.C +++ b/cinelerra-5.0/plugins/brighttheme/brighttheme.C @@ -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() diff --git a/cinelerra-5.0/plugins/defaulttheme/defaulttheme.C b/cinelerra-5.0/plugins/defaulttheme/defaulttheme.C index b57f70d3..67f6377a 100644 --- a/cinelerra-5.0/plugins/defaulttheme/defaulttheme.C +++ b/cinelerra-5.0/plugins/defaulttheme/defaulttheme.C @@ -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() diff --git a/cinelerra-5.0/plugins/microtheme/microtheme.C b/cinelerra-5.0/plugins/microtheme/microtheme.C index f1b95493..37e70eba 100644 --- a/cinelerra-5.0/plugins/microtheme/microtheme.C +++ b/cinelerra-5.0/plugins/microtheme/microtheme.C @@ -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; } diff --git a/cinelerra-5.0/plugins/suv/suv.C b/cinelerra-5.0/plugins/suv/suv.C index 6937885e..586c4dcd 100644 --- a/cinelerra-5.0/plugins/suv/suv.C +++ b/cinelerra-5.0/plugins/suv/suv.C @@ -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; diff --git a/cinelerra-5.0/plugins/titler/title.C b/cinelerra-5.0/plugins/titler/title.C index 3b25e1bf..8ccdb2a3 100644 --- a/cinelerra-5.0/plugins/titler/title.C +++ b/cinelerra-5.0/plugins/titler/title.C @@ -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); -- 2.26.2