summaryrefslogtreecommitdiff
path: root/libs/plugins
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2019-12-08 15:21:30 +0100
committerRobin Gareus <robin@gareus.org>2019-12-08 15:22:00 +0100
commit7253f304e2f6d4016ae03a901fef393b61cd3bd5 (patch)
tree37d7e1d6a2b7536310d982fffaad00f3ac7b315a /libs/plugins
parentdca3f7dd97a057b1cd449b6eccbfbbfcd5e7998b (diff)
Add support for LV2 state:freePath feature
This fixes a memory-leak issue for Windows builds. see also https://github.com/drobilla/lilv/issues/14
Diffstat (limited to 'libs/plugins')
-rw-r--r--libs/plugins/a-fluidsynth.lv2/a-fluidsynth.cc39
1 files changed, 31 insertions, 8 deletions
diff --git a/libs/plugins/a-fluidsynth.lv2/a-fluidsynth.cc b/libs/plugins/a-fluidsynth.lv2/a-fluidsynth.cc
index 1ec184fdf3..9890317a43 100644
--- a/libs/plugins/a-fluidsynth.lv2/a-fluidsynth.cc
+++ b/libs/plugins/a-fluidsynth.lv2/a-fluidsynth.cc
@@ -727,7 +727,10 @@ save (LV2_Handle instance,
return LV2_STATE_ERR_NO_PROPERTY;
}
- LV2_State_Map_Path* map_path = NULL;
+ LV2_State_Map_Path* map_path = NULL;
+#ifdef LV2_STATE__freePath
+ LV2_State_Free_Path* free_path = NULL;
+#endif
for (int i = 0; features[i]; ++i) {
if (!strcmp (features[i]->URI, LV2_STATE__mapPath)) {
@@ -743,9 +746,15 @@ save (LV2_Handle instance,
store (handle, self->afs_sf2file,
apath, strlen (apath) + 1,
self->atom_Path, LV2_STATE_IS_POD);
-
-#ifndef _WIN32 // TODO need lilv_free() -- https://github.com/drobilla/lilv/issues/14
- free (apath);
+#ifdef LV2_STATE__freePath
+ if (free_path) {
+ free_path->free_path (free_path->handle, apath);
+ } else
+#endif
+#ifndef _WIN32 // https://github.com/drobilla/lilv/issues/14
+ {
+ free (apath);
+ }
#endif
return LV2_STATE_SUCCESS;
@@ -764,12 +773,20 @@ restore (LV2_Handle instance,
return LV2_STATE_ERR_UNKNOWN;
}
- LV2_State_Map_Path* map_path = NULL;
+ LV2_State_Map_Path* map_path = NULL;
+#ifdef LV2_STATE__freePath
+ LV2_State_Free_Path* free_path = NULL;
+#endif
for (int i = 0; features[i]; ++i) {
if (!strcmp (features[i]->URI, LV2_STATE__mapPath)) {
map_path = (LV2_State_Map_Path*) features[i]->data;
}
+#ifdef LV2_STATE__freePath
+ else if (!strcmp(features[i]->URI, LV2_STATE__freePath)) {
+ free_path = (LV2_State_Free_Path*)features[i]->data;
+ }
+#endif
}
if (!map_path) {
@@ -784,11 +801,17 @@ restore (LV2_Handle instance,
if (value) {
char* apath = map_path->absolute_path (map_path->handle, (const char*) value);
strncpy (self->queue_sf2_file_path, apath, 1023);
- printf ("XXX %s -> %s\n", (const char*) value, apath);
self->queue_sf2_file_path[1023] = '\0';
self->queue_reinit = true;
-#ifndef _WIN32 // TODO need lilv_free() -- https://github.com/drobilla/lilv/issues/14
- free (apath);
+#ifdef LV2_STATE__freePath
+ if (free_path) {
+ free_path->free_path (free_path->handle, apath);
+ } else
+#endif
+#ifndef _WIN32 // https://github.com/drobilla/lilv/issues/14
+ {
+ free (apath);
+ }
#endif
}
return LV2_STATE_SUCCESS;