From 0e96d84079c1792523d99b6bbec5878d11f5c8e4 Mon Sep 17 00:00:00 2001 From: Tim Mayberry Date: Mon, 16 Jun 2014 20:39:45 +1000 Subject: Change PBD::PathScanner API to return results by value to avoid inadvertent memory leaks --- libs/ardour/ardour/session.h | 4 +- libs/ardour/lv2_plugin.cc | 21 +++---- libs/ardour/panner_manager.cc | 9 +-- libs/ardour/plugin_manager.cc | 125 ++++++++++++++---------------------------- libs/ardour/session_state.cc | 88 ++++++++++++----------------- libs/ardour/template_utils.cc | 28 ++++------ 6 files changed, 100 insertions(+), 175 deletions(-) (limited to 'libs/ardour') diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h index 08d0ec1e4e..0dd986226b 100644 --- a/libs/ardour/ardour/session.h +++ b/libs/ardour/ardour/session.h @@ -402,8 +402,8 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop PBD::Signal0 StateReady; PBD::Signal0 SaveSession; - std::vector* possible_states() const; - static std::vector* possible_states (std::string path); + std::vector possible_states() const; + static std::vector possible_states (std::string path); XMLNode& get_state(); int set_state(const XMLNode& node, int version); // not idempotent diff --git a/libs/ardour/lv2_plugin.cc b/libs/ardour/lv2_plugin.cc index 8fac9369b0..d68c4e5077 100644 --- a/libs/ardour/lv2_plugin.cc +++ b/libs/ardour/lv2_plugin.cc @@ -2013,23 +2013,20 @@ void LV2World::load_bundled_plugins() { if (!_bundle_checked) { - cout << "Scanning folders for bundled LV2s: " << ARDOUR::lv2_bundled_search_path().to_string() << endl; PathScanner scanner; - vector *plugin_objects = scanner (ARDOUR::lv2_bundled_search_path().to_string(), lv2_filter, 0, true, true); - if (plugin_objects) { - for ( vector::iterator x = plugin_objects->begin(); x != plugin_objects->end (); ++x) { + cout << "Scanning folders for bundled LV2s: " << ARDOUR::lv2_bundled_search_path().to_string() << endl; + + vector plugin_objects = scanner (ARDOUR::lv2_bundled_search_path().to_string(), lv2_filter, 0, true, true); + for ( vector::iterator x = plugin_objects.begin(); x != plugin_objects.end (); ++x) { #ifdef PLATFORM_WINDOWS - string uri = "file:///" + **x + "/"; + string uri = "file:///" + *x + "/"; #else - string uri = "file://" + **x + "/"; + string uri = "file://" + *x + "/"; #endif - LilvNode *node = lilv_new_uri(world, uri.c_str()); - lilv_world_load_bundle(world, node); - lilv_node_free(node); - } + LilvNode *node = lilv_new_uri(world, uri.c_str()); + lilv_world_load_bundle(world, node); + lilv_node_free(node); } - vector_delete (plugin_objects); - delete (plugin_objects); _bundle_checked = true; } diff --git a/libs/ardour/panner_manager.cc b/libs/ardour/panner_manager.cc index 95136c2951..2988a8ab46 100644 --- a/libs/ardour/panner_manager.cc +++ b/libs/ardour/panner_manager.cc @@ -91,19 +91,16 @@ void PannerManager::discover_panners () { PathScanner scanner; - std::vector *panner_modules; + std::vector panner_modules; std::string search_path = panner_search_path().to_string(); DEBUG_TRACE (DEBUG::Panning, string_compose (_("looking for panners in %1\n"), search_path)); panner_modules = scanner (search_path, panner_filter, 0, false, true, 1, true); - for (vector::iterator i = panner_modules->begin(); i != panner_modules->end(); ++i) { - panner_discover (**i); + for (vector::iterator i = panner_modules.begin(); i != panner_modules.end(); ++i) { + panner_discover (*i); } - - vector_delete (panner_modules); - delete (panner_modules); } int diff --git a/libs/ardour/plugin_manager.cc b/libs/ardour/plugin_manager.cc index c638ff2e86..c1e596ff3d 100644 --- a/libs/ardour/plugin_manager.cc +++ b/libs/ardour/plugin_manager.cc @@ -243,31 +243,23 @@ PluginManager::clear_vst_cache () #ifdef WINDOWS_VST_SUPPORT { PathScanner scanner; - vector *fsi_files; + vector fsi_files; fsi_files = scanner (Config->get_plugin_path_vst(), "\\.fsi$", true, true, -1, false); - if (fsi_files) { - for (vector::iterator i = fsi_files->begin(); i != fsi_files->end (); ++i) { - ::g_unlink((*i)->c_str()); - } + for (vector::iterator i = fsi_files.begin(); i != fsi_files.end (); ++i) { + ::g_unlink(i->c_str()); } - vector_delete(fsi_files); - delete(fsi_files); } #endif #ifdef LXVST_SUPPORT { PathScanner scanner; - vector *fsi_files; + vector fsi_files; fsi_files = scanner (Config->get_plugin_path_lxvst(), "\\.fsi$", true, true, -1, false); - if (fsi_files) { - for (vector::iterator i = fsi_files->begin(); i != fsi_files->end (); ++i) { - ::g_unlink((*i)->c_str()); - } + for (vector::iterator i = fsi_files.begin(); i != fsi_files.end (); ++i) { + ::g_unlink(i->c_str()); } - vector_delete(fsi_files); - delete(fsi_files); } #endif @@ -275,15 +267,11 @@ PluginManager::clear_vst_cache () { string personal = get_personal_vst_info_cache_dir(); PathScanner scanner; - vector *fsi_files; + vector fsi_files; fsi_files = scanner (personal, "\\.fsi$", true, true, -1, false); - if (fsi_files) { - for (vector::iterator i = fsi_files->begin(); i != fsi_files->end (); ++i) { - ::g_unlink((*i)->c_str()); - } + for (vector::iterator i = fsi_files.begin(); i != fsi_files.end (); ++i) { + ::g_unlink(i->c_str()); } - vector_delete(fsi_files); - delete(fsi_files); } #endif } @@ -294,31 +282,23 @@ PluginManager::clear_vst_blacklist () #ifdef WINDOWS_VST_SUPPORT { PathScanner scanner; - vector *fsi_files; + vector fsi_files; fsi_files = scanner (Config->get_plugin_path_vst(), "\\.fsb$", true, true, -1, false); - if (fsi_files) { - for (vector::iterator i = fsi_files->begin(); i != fsi_files->end (); ++i) { - ::g_unlink((*i)->c_str()); - } + for (vector::iterator i = fsi_files.begin(); i != fsi_files.end (); ++i) { + ::g_unlink(i->c_str()); } - vector_delete(fsi_files); - delete(fsi_files); } #endif #ifdef LXVST_SUPPORT { PathScanner scanner; - vector *fsi_files; + vector fsi_files; fsi_files = scanner (Config->get_plugin_path_lxvst(), "\\.fsb$", true, true, -1, false); - if (fsi_files) { - for (vector::iterator i = fsi_files->begin(); i != fsi_files->end (); ++i) { - ::g_unlink((*i)->c_str()); - } + for (vector::iterator i = fsi_files.begin(); i != fsi_files.end (); ++i) { + ::g_unlink(i->c_str()); } - vector_delete(fsi_files); - delete(fsi_files); } #endif @@ -327,15 +307,11 @@ PluginManager::clear_vst_blacklist () string personal = get_personal_vst_blacklist_dir(); PathScanner scanner; - vector *fsi_files; + vector fsi_files; fsi_files = scanner (personal, "\\.fsb$", true, true, -1, false); - if (fsi_files) { - for (vector::iterator i = fsi_files->begin(); i != fsi_files->end (); ++i) { - ::g_unlink((*i)->c_str()); - } + for (vector::iterator i = fsi_files.begin(); i != fsi_files.end (); ++i) { + ::g_unlink(i->c_str()); } - vector_delete(fsi_files); - delete(fsi_files); } #endif } @@ -410,8 +386,8 @@ PluginManager::add_presets(string domain) { #ifdef HAVE_LRDF PathScanner scanner; - vector *presets; - vector::iterator x; + vector presets; + vector::iterator x; char* envvar; if ((envvar = getenv ("HOME")) == 0) { @@ -421,17 +397,13 @@ PluginManager::add_presets(string domain) string path = string_compose("%1/.%2/rdf", envvar, domain); presets = scanner (path, rdf_filter, 0, false, true); - if (presets) { - for (x = presets->begin(); x != presets->end (); ++x) { - string file = "file:" + **x; - if (lrdf_read_file(file.c_str())) { - warning << string_compose(_("Could not parse rdf file: %1"), *x) << endmsg; - } + for (x = presets.begin(); x != presets.end (); ++x) { + string file = "file:" + *x; + if (lrdf_read_file(file.c_str())) { + warning << string_compose(_("Could not parse rdf file: %1"), *x) << endmsg; } - - vector_delete (presets); - delete (presets); } + #endif } @@ -440,22 +412,17 @@ PluginManager::add_lrdf_data (const string &path) { #ifdef HAVE_LRDF PathScanner scanner; - vector* rdf_files; - vector::iterator x; + vector rdf_files; + vector::iterator x; rdf_files = scanner (path, rdf_filter, 0, false, true); - if (rdf_files) { - for (x = rdf_files->begin(); x != rdf_files->end (); ++x) { - const string uri(string("file://") + **x); + for (x = rdf_files.begin(); x != rdf_files.end (); ++x) { + const string uri(string("file://") + *x); - if (lrdf_read_file(uri.c_str())) { - warning << "Could not parse rdf file: " << uri << endmsg; - } + if (lrdf_read_file(uri.c_str())) { + warning << "Could not parse rdf file: " << uri << endmsg; } - - vector_delete (rdf_files); - delete (rdf_files); } #endif } @@ -662,22 +629,17 @@ int PluginManager::windows_vst_discover_from_path (string path, bool cache_only) { PathScanner scanner; - vector *plugin_objects; - vector::iterator x; + vector plugin_objects; + vector::iterator x; int ret = 0; DEBUG_TRACE (DEBUG::PluginManager, string_compose ("detecting Windows VST plugins along %1\n", path)); plugin_objects = scanner (Config->get_plugin_path_vst(), windows_vst_filter, 0, false, true); - if (plugin_objects) { - for (x = plugin_objects->begin(); x != plugin_objects->end (); ++x) { - ARDOUR::PluginScanMessage(_("VST"), **x, !cache_only && !cancelled()); - windows_vst_discover (**x, cache_only || cancelled()); - } - - vector_delete (plugin_objects); - delete (plugin_objects); + for (x = plugin_objects.begin(); x != plugin_objects.end (); ++x) { + ARDOUR::PluginScanMessage(_("VST"), *x, !cache_only && !cancelled()); + windows_vst_discover (*x, cache_only || cancelled()); } return ret; @@ -783,8 +745,8 @@ int PluginManager::lxvst_discover_from_path (string path, bool cache_only) { PathScanner scanner; - vector *plugin_objects; - vector::iterator x; + vector plugin_objects; + vector::iterator x; int ret = 0; #ifndef NDEBUG @@ -795,14 +757,9 @@ PluginManager::lxvst_discover_from_path (string path, bool cache_only) plugin_objects = scanner (Config->get_plugin_path_lxvst(), lxvst_filter, 0, false, true); - if (plugin_objects) { - for (x = plugin_objects->begin(); x != plugin_objects->end (); ++x) { - ARDOUR::PluginScanMessage(_("LXVST"), **x, !cache_only && !cancelled()); - lxvst_discover (**x, cache_only || cancelled()); - } - - vector_delete (plugin_objects); - delete (plugin_objects); + for (x = plugin_objects.begin(); x != plugin_objects.end (); ++x) { + ARDOUR::PluginScanMessage(_("LXVST"), *x, !cache_only && !cancelled()); + lxvst_discover (*x, cache_only || cancelled()); } return ret; diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc index 8999927729..9151ebf5eb 100644 --- a/libs/ardour/session_state.cc +++ b/libs/ardour/session_state.cc @@ -2299,16 +2299,10 @@ state_file_filter (const string &str, void* /*arg*/) str.find (statefile_suffix) == (str.length() - strlen (statefile_suffix))); } -struct string_cmp { - bool operator()(const string* a, const string* b) { - return *a < *b; - } -}; - -static string* -remove_end(string* state) +static string +remove_end(string state) { - string statename(*state); + string statename(state); string::size_type start,end; if ((start = statename.find_last_of (G_DIR_SEPARATOR)) != string::npos) { @@ -2319,24 +2313,23 @@ remove_end(string* state) end = statename.length(); } - return new string(statename.substr (0, end)); + return string(statename.substr (0, end)); } -vector * +vector Session::possible_states (string path) { PathScanner scanner; - vector* states = scanner (path, state_file_filter, 0, false, false); + vector states = scanner (path, state_file_filter, 0, false, false); - transform(states->begin(), states->end(), states->begin(), remove_end); + transform(states.begin(), states.end(), states.begin(), remove_end); - string_cmp cmp; - sort (states->begin(), states->end(), cmp); + sort (states.begin(), states.end()); return states; } -vector * +vector Session::possible_states () const { return possible_states(_path); @@ -2561,7 +2554,7 @@ int Session::find_all_sources_across_snapshots (set& result, bool exclude_this_snapshot) { PathScanner scanner; - vector* state_files; + vector state_files; string ripped; string this_snapshot_path; @@ -2575,7 +2568,7 @@ Session::find_all_sources_across_snapshots (set& result, bool exclude_th state_files = scanner (ripped, accept_all_state_files, (void *) 0, true, true); - if (state_files == 0) { + if (state_files.empty()) { /* impossible! */ return 0; } @@ -2584,13 +2577,13 @@ Session::find_all_sources_across_snapshots (set& result, bool exclude_th this_snapshot_path += legalize_for_path (_current_snapshot_name); this_snapshot_path += statefile_suffix; - for (vector::iterator i = state_files->begin(); i != state_files->end(); ++i) { + for (vector::iterator i = state_files.begin(); i != state_files.end(); ++i) { - if (exclude_this_snapshot && **i == this_snapshot_path) { + if (exclude_this_snapshot && *i == this_snapshot_path) { continue; } - if (find_all_sources (**i, result) < 0) { + if (find_all_sources (*i, result) < 0) { return -1; } } @@ -2645,8 +2638,8 @@ Session::cleanup_sources (CleanupReport& rep) string midi_path; vector::iterator i; vector::iterator nexti; - vector* candidates; - vector* candidates2; + vector candidates; + vector candidates2; vector unused; set all_sources; bool used; @@ -2733,16 +2726,9 @@ Session::cleanup_sources (CleanupReport& rep) /* merge them */ - if (candidates) { - if (candidates2) { - for (vector::iterator i = candidates2->begin(); i != candidates2->end(); ++i) { - candidates->push_back (*i); - } - delete candidates2; - } - } else { - candidates = candidates2; // might still be null - } + for (vector::iterator i = candidates2.begin(); i != candidates2.end(); ++i) { + candidates.push_back (*i); + } /* find all sources, but don't use this snapshot because the state file on disk still references sources we may have already @@ -2782,32 +2768,26 @@ Session::cleanup_sources (CleanupReport& rep) i = tmp; } - if (candidates) { - for (vector::iterator x = candidates->begin(); x != candidates->end(); ++x) { + for (vector::iterator x = candidates.begin(); x != candidates.end(); ++x) { - used = false; - spath = **x; + used = false; + spath = *x; - for (set::iterator i = all_sources.begin(); i != all_sources.end(); ++i) { + for (set::iterator i = all_sources.begin(); i != all_sources.end(); ++i) { - tmppath1 = canonical_path (spath); - tmppath2 = canonical_path ((*i)); - - if (tmppath1 == tmppath2) { - used = true; - break; - } - } + tmppath1 = canonical_path (spath); + tmppath2 = canonical_path ((*i)); - if (!used) { - unused.push_back (spath); - } - - delete *x; - } + if (tmppath1 == tmppath2) { + used = true; + break; + } + } - delete candidates; - } + if (!used) { + unused.push_back (spath); + } + } /* now try to move all unused files into the "dead" directory(ies) */ diff --git a/libs/ardour/template_utils.cc b/libs/ardour/template_utils.cc index 86881adfc3..20530ca9cc 100644 --- a/libs/ardour/template_utils.cc +++ b/libs/ardour/template_utils.cc @@ -81,21 +81,21 @@ session_template_dir_to_file (string const & dir) void find_session_templates (vector& template_names) { - vector *templates; + vector templates; PathScanner scanner; Searchpath spath (template_search_path()); templates = scanner (spath.to_string(), template_filter, 0, true, true); - if (!templates) { + if (templates.empty()) { cerr << "Found nothing along " << spath.to_string() << endl; return; } - cerr << "Found " << templates->size() << " along " << spath.to_string() << endl; + cerr << "Found " << templates.size() << " along " << spath.to_string() << endl; - for (vector::iterator i = templates->begin(); i != templates->end(); ++i) { - string file = session_template_dir_to_file (**i); + for (vector::iterator i = templates.begin(); i != templates.end(); ++i) { + string file = session_template_dir_to_file (*i); XMLTree tree; @@ -105,31 +105,28 @@ find_session_templates (vector& template_names) TemplateInfo rti; - rti.name = basename_nosuffix (**i); - rti.path = **i; + rti.name = basename_nosuffix (*i); + rti.path = *i; template_names.push_back (rti); } - - vector_delete (templates); - delete templates; } void find_route_templates (vector& template_names) { - vector *templates; + vector templates; PathScanner scanner; Searchpath spath (route_template_search_path()); templates = scanner (spath.to_string(), route_template_filter, 0, false, true); - if (!templates) { + if (templates.empty()) { return; } - for (vector::iterator i = templates->begin(); i != templates->end(); ++i) { - string fullpath = *(*i); + for (vector::iterator i = templates.begin(); i != templates.end(); ++i) { + string fullpath = *i; XMLTree tree; @@ -146,9 +143,6 @@ find_route_templates (vector& template_names) template_names.push_back (rti); } - - vector_delete (templates); - delete templates; } } -- cgit v1.2.3