From 5ae973b8f7f38f32a28b6b23bfe622b51bb64c51 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 18 Jan 2020 17:36:06 +0100 Subject: Fix memory leak when dyn-manifest has no plugins --- src/lilv_internal.h | 2 ++ src/plugin.c | 11 +---------- src/world.c | 19 ++++++++++++++++++- 3 files changed, 21 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/lilv_internal.h b/src/lilv_internal.h index 368d7ed..3a36837 100644 --- a/src/lilv_internal.h +++ b/src/lilv_internal.h @@ -424,6 +424,8 @@ lilv_dlfunc(void* handle, const char* symbol) #ifdef LILV_DYN_MANIFEST static const LV2_Feature* const dman_features = { NULL }; + +void lilv_dynmanifest_free(LilvDynManifest* dynmanifest); #endif #define LILV_ERROR(str) fprintf(stderr, "%s(): error: " str, \ diff --git a/src/plugin.c b/src/plugin.c index 3f27a6b..0743cd8 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -100,16 +100,7 @@ lilv_plugin_free(LilvPlugin* plugin) { #ifdef LILV_DYN_MANIFEST if (plugin->dynmanifest && --plugin->dynmanifest->refs == 0) { - typedef int (*CloseFunc)(LV2_Dyn_Manifest_Handle); - CloseFunc close_func = (CloseFunc)lilv_dlfunc(plugin->dynmanifest->lib, - "lv2_dyn_manifest_close"); - if (close_func) { - close_func(plugin->dynmanifest->handle); - } - - dlclose(plugin->dynmanifest->lib); - lilv_node_free(plugin->dynmanifest->bundle); - free(plugin->dynmanifest); + lilv_dynmanifest_free(plugin->dynmanifest); } #endif diff --git a/src/world.c b/src/world.c index 970111c..22d165a 100644 --- a/src/world.c +++ b/src/world.c @@ -619,7 +619,7 @@ lilv_world_load_dyn_manifest(LilvWorld* world, lilv_world_add_plugin(world, plug, manifest, desc, bundle_node); } if (desc->refs == 0) { - free(desc); + lilv_dynmanifest_free(desc); } sord_iter_free(p); sord_free(plugins); @@ -630,6 +630,23 @@ lilv_world_load_dyn_manifest(LilvWorld* world, #endif // LILV_DYN_MANIFEST } +#ifdef LILV_DYN_MANIFEST +void +lilv_dynmanifest_free(LilvDynManifest* dynmanifest) +{ + typedef int (*CloseFunc)(LV2_Dyn_Manifest_Handle); + CloseFunc close_func = (CloseFunc)lilv_dlfunc(dynmanifest->lib, + "lv2_dyn_manifest_close"); + if (close_func) { + close_func(dynmanifest->handle); + } + + dlclose(dynmanifest->lib); + lilv_node_free(dynmanifest->bundle); + free(dynmanifest); +} +#endif // LILV_DYN_MANIFEST + LilvNode* lilv_world_get_manifest_uri(LilvWorld* world, const LilvNode* bundle_uri) { -- cgit v1.2.1