changeset 467:bd8484e19353 vampipe

Fix long-standing memory leaks (parameter descriptors and feature list container) in plugin adapter
author Chris Cannam
date Fri, 14 Oct 2016 09:32:11 +0100
parents a94ab90dfd53
children a75fdb8b368c
files src/vamp-sdk/PluginAdapter.cpp
diffstat 1 files changed, 27 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/src/vamp-sdk/PluginAdapter.cpp	Thu Oct 13 17:06:53 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));