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
This commit is contained in:
parent
dca3f7dd97
commit
7253f304e2
|
@ -727,7 +727,10 @@ save (LV2_Handle instance,
|
||||||
return LV2_STATE_ERR_NO_PROPERTY;
|
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) {
|
for (int i = 0; features[i]; ++i) {
|
||||||
if (!strcmp (features[i]->URI, LV2_STATE__mapPath)) {
|
if (!strcmp (features[i]->URI, LV2_STATE__mapPath)) {
|
||||||
|
@ -743,9 +746,15 @@ save (LV2_Handle instance,
|
||||||
store (handle, self->afs_sf2file,
|
store (handle, self->afs_sf2file,
|
||||||
apath, strlen (apath) + 1,
|
apath, strlen (apath) + 1,
|
||||||
self->atom_Path, LV2_STATE_IS_POD);
|
self->atom_Path, LV2_STATE_IS_POD);
|
||||||
|
#ifdef LV2_STATE__freePath
|
||||||
#ifndef _WIN32 // TODO need lilv_free() -- https://github.com/drobilla/lilv/issues/14
|
if (free_path) {
|
||||||
free (apath);
|
free_path->free_path (free_path->handle, apath);
|
||||||
|
} else
|
||||||
|
#endif
|
||||||
|
#ifndef _WIN32 // https://github.com/drobilla/lilv/issues/14
|
||||||
|
{
|
||||||
|
free (apath);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return LV2_STATE_SUCCESS;
|
return LV2_STATE_SUCCESS;
|
||||||
|
@ -764,12 +773,20 @@ restore (LV2_Handle instance,
|
||||||
return LV2_STATE_ERR_UNKNOWN;
|
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) {
|
for (int i = 0; features[i]; ++i) {
|
||||||
if (!strcmp (features[i]->URI, LV2_STATE__mapPath)) {
|
if (!strcmp (features[i]->URI, LV2_STATE__mapPath)) {
|
||||||
map_path = (LV2_State_Map_Path*) features[i]->data;
|
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) {
|
if (!map_path) {
|
||||||
|
@ -784,11 +801,17 @@ restore (LV2_Handle instance,
|
||||||
if (value) {
|
if (value) {
|
||||||
char* apath = map_path->absolute_path (map_path->handle, (const char*) value);
|
char* apath = map_path->absolute_path (map_path->handle, (const char*) value);
|
||||||
strncpy (self->queue_sf2_file_path, apath, 1023);
|
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_sf2_file_path[1023] = '\0';
|
||||||
self->queue_reinit = true;
|
self->queue_reinit = true;
|
||||||
#ifndef _WIN32 // TODO need lilv_free() -- https://github.com/drobilla/lilv/issues/14
|
#ifdef LV2_STATE__freePath
|
||||||
free (apath);
|
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
|
#endif
|
||||||
}
|
}
|
||||||
return LV2_STATE_SUCCESS;
|
return LV2_STATE_SUCCESS;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user