# HG changeset patch # User Chris Cannam # Date 1476433931 -3600 # Node ID 1cdcd2ee3d9132ae5b843ee28dbdc0150f2fdb83 # Parent 7cf38d7ad81db97378ba60306f846d5cb0434094 Fix long-standing memory leaks (parameter descriptors and feature list container) in plugin adapter diff -r 7cf38d7ad81d -r 1cdcd2ee3d91 src/vamp-sdk/PluginAdapter.cpp --- a/src/vamp-sdk/PluginAdapter.cpp Mon Oct 10 15:52:40 2016 +0100 +++ b/src/vamp-sdk/PluginAdapter.cpp Fri Oct 14 09:32:11 2016 +0100 @@ -166,7 +166,7 @@ #endif if (m_populated) return &m_descriptor; - + Plugin *plugin = m_base->createPlugin(48000); if (!plugin) { @@ -298,6 +298,7 @@ } free((void *)desc->valueNames); } + free((void *)desc); } free((void *)m_descriptor.parameters); @@ -603,6 +604,7 @@ if (m_pluginOutputs[plugin]) { outputCount = m_pluginOutputs[plugin]->size(); } + std::cerr << "cleanup: " << outputCount << " output(s)" << std::endl; VampFeatureList *list = m_fs[plugin]; for (unsigned int i = 0; i < outputCount; ++i) { for (unsigned int j = 0; j < m_fsizes[plugin][i]; ++j) { @@ -615,6 +617,7 @@ } if (list[i].features) free(list[i].features); } + if (list) free((void *)list); m_fs.erase(plugin); m_fsizes.erase(plugin); m_fvsizes.erase(plugin); @@ -849,12 +852,16 @@ void PluginAdapterBase::Impl::resizeFS(Plugin *plugin, int n) { -// std::cerr << "PluginAdapterBase::Impl::resizeFS(" << plugin << ", " << n << ")" << std::endl; +#ifdef DEBUG_PLUGIN_ADAPTER + std::cerr << "PluginAdapterBase::Impl::resizeFS(" << plugin << ", " << n << ")" << std::endl; +#endif int i = m_fsizes[plugin].size(); if (i >= n) return; -// std::cerr << "resizing from " << i << std::endl; +#ifdef DEBUG_PLUGIN_ADAPTER + std::cerr << "resizing from " << i << std::endl; +#endif m_fs[plugin] = (VampFeatureList *)realloc (m_fs[plugin], n * sizeof(VampFeatureList)); @@ -871,13 +878,17 @@ void PluginAdapterBase::Impl::resizeFL(Plugin *plugin, int n, size_t sz) { -// std::cerr << "PluginAdapterBase::Impl::resizeFL(" << plugin << ", " << n << ", " -// << sz << ")" << std::endl; - +#ifdef DEBUG_PLUGIN_ADAPTER + std::cerr << "PluginAdapterBase::Impl::resizeFL(" << plugin << ", " << n << ", " + << sz << ")" << std::endl; +#endif + size_t i = m_fsizes[plugin][n]; if (i >= sz) return; -// std::cerr << "resizing from " << i << std::endl; +#ifdef DEBUG_PLUGIN_ADAPTER + std::cerr << "resizing from " << i << std::endl; +#endif m_fs[plugin][n].features = (VampFeatureUnion *)realloc (m_fs[plugin][n].features, 2 * sz * sizeof(VampFeatureUnion)); @@ -896,14 +907,18 @@ void PluginAdapterBase::Impl::resizeFV(Plugin *plugin, int n, int j, size_t sz) { -// std::cerr << "PluginAdapterBase::Impl::resizeFV(" << plugin << ", " << n << ", " -// << j << ", " << sz << ")" << std::endl; - +#ifdef DEBUG_PLUGIN_ADAPTER + std::cerr << "PluginAdapterBase::Impl::resizeFV(" << plugin << ", " << n << ", " + << j << ", " << sz << ")" << std::endl; +#endif + size_t i = m_fvsizes[plugin][n][j]; if (i >= sz) return; -// std::cerr << "resizing from " << i << std::endl; - +#ifdef DEBUG_PLUGIN_ADAPTER + std::cerr << "resizing from " << i << std::endl; +#endif + m_fs[plugin][n].features[j].v1.values = (float *)realloc (m_fs[plugin][n].features[j].v1.values, sz * sizeof(float));