summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2016-09-18 15:13:52 -0400
committerDavid Robillard <d@drobilla.net>2016-09-18 15:13:52 -0400
commit7ce645cfe6fffef55eb43e1e2b63e4ac41c8581c (patch)
treedd5b03025c8984da6b52f5d1653ac140bf81c7e1 /src
parent7a68f1e59abd84574d8b8ccf6289b6c01bf428c6 (diff)
downloadlilv-7ce645cfe6fffef55eb43e1e2b63e4ac41c8581c.tar.gz
lilv-7ce645cfe6fffef55eb43e1e2b63e4ac41c8581c.tar.bz2
lilv-7ce645cfe6fffef55eb43e1e2b63e4ac41c8581c.zip
Fix memory, file, and library leaks
Diffstat (limited to 'src')
-rw-r--r--src/instance.c1
-rw-r--r--src/lib.c1
-rw-r--r--src/plugin.c3
-rw-r--r--src/state.c13
-rw-r--r--src/util.c1
5 files changed, 14 insertions, 5 deletions
diff --git a/src/instance.c b/src/instance.c
index 9f27fa6..d05defd 100644
--- a/src/instance.c
+++ b/src/instance.c
@@ -78,6 +78,7 @@ lilv_plugin_instantiate(const LilvPlugin* plugin,
if (result->lv2_handle == NULL) {
// Failed to instantiate
free(result);
+ lilv_lib_close(lib);
return NULL;
}
diff --git a/src/lib.c b/src/lib.c
index 8470684..f828d4f 100644
--- a/src/lib.c
+++ b/src/lib.c
@@ -57,6 +57,7 @@ lilv_lib_open(LilvWorld* world,
desc = ldf(bundle_path, features);
if (!desc) {
LILV_ERRORF("Call to %s:lv2_lib_descriptor failed\n", lib_path);
+ dlclose(lib);
lilv_free(lib_path);
return NULL;
}
diff --git a/src/plugin.c b/src/plugin.c
index f8ab26a..5e10d7c 100644
--- a/src/plugin.c
+++ b/src/plugin.c
@@ -210,6 +210,8 @@ lilv_plugin_load(LilvPlugin* p)
if (st > SERD_FAILURE) {
p->loaded = true;
p->parse_errors = true;
+ serd_reader_free(reader);
+ serd_env_free(env);
return;
}
@@ -287,6 +289,7 @@ lilv_plugin_load_ports_if_necessary(const LilvPlugin* const_p)
lilv_node_as_uri(p->plugin_uri),
lilv_node_as_string(symbol));
lilv_node_free(symbol);
+ lilv_node_free(index);
lilv_plugin_free_ports(p);
break;
}
diff --git a/src/state.c b/src/state.c
index b852a31..7a8abc0 100644
--- a/src/state.c
+++ b/src/state.c
@@ -245,6 +245,7 @@ abstract_path(LV2_State_Map_Path_Handle handle,
char* copy = lilv_get_latest_copy(real_path, cpath);
if (!copy || !lilv_file_equals(real_path, copy)) {
// No recent enough copy, make a new one
+ free(copy);
copy = lilv_find_free_path(cpath, lilv_path_exists, NULL);
const int st = lilv_copy_file(real_path, copy);
if (st) {
@@ -1204,11 +1205,13 @@ lilv_state_delete(LilvWorld* world,
}
static void
-free_property_array(PropertyArray* array)
+free_property_array(LilvState* state, PropertyArray* array)
{
for (uint32_t i = 0; i < array->n; ++i) {
- if (array->props[i].flags & LV2_STATE_IS_POD) {
- free(array->props[i].value);
+ Property* prop = &array->props[i];
+ if ((prop->flags & LV2_STATE_IS_POD) ||
+ prop->type == state->atom_Path) {
+ free(prop->value);
}
}
free(array->props);
@@ -1218,8 +1221,8 @@ LILV_API void
lilv_state_free(LilvState* state)
{
if (state) {
- free_property_array(&state->props);
- free_property_array(&state->metadata);
+ free_property_array(state, &state->props);
+ free_property_array(state, &state->metadata);
for (uint32_t i = 0; i < state->n_values; ++i) {
free(state->values[i].value);
free(state->values[i].symbol);
diff --git a/src/util.c b/src/util.c
index a0019cf..864bcbb 100644
--- a/src/util.c
+++ b/src/util.c
@@ -299,6 +299,7 @@ lilv_copy_file(const char* src, const char* dst)
FILE* out = fopen(dst, "w");
if (!out) {
+ fclose(in);
return errno;
}