summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2012-01-18 18:14:18 +0000
committerDavid Robillard <d@drobilla.net>2012-01-18 18:14:18 +0000
commite4d3f6140cc167580ec43de6fc3ea4562aaba63e (patch)
tree2ab0a6a529584a40ef7ed78c35aa5b1cb66fdba5
parent32c2579e5a4aa32df26974f7f31063f9f499e906 (diff)
downloadlilv-e4d3f6140cc167580ec43de6fc3ea4562aaba63e.tar.gz
lilv-e4d3f6140cc167580ec43de6fc3ea4562aaba63e.tar.bz2
lilv-e4d3f6140cc167580ec43de6fc3ea4562aaba63e.zip
Fix memory leaks.
git-svn-id: http://svn.drobilla.net/lad/trunk/lilv@3966 a436a847-0d15-0410-975c-d299462d15a1
-rw-r--r--src/state.c13
-rw-r--r--src/util.c13
-rw-r--r--test/lilv_test.c48
-rw-r--r--test/test_plugin.c5
4 files changed, 49 insertions, 30 deletions
diff --git a/src/state.c b/src/state.c
index 5f8a13f..270b9bb 100644
--- a/src/state.c
+++ b/src/state.c
@@ -203,6 +203,7 @@ abstract_path(LV2_State_Map_Path_Handle handle,
copy = lilv_find_free_path(real_path, lilv_path_exists, NULL);
lilv_copy_file(real_path, copy);
}
+ free(real_path);
real_path = copy;
// Refer to the latest copy in plugin state
@@ -852,6 +853,9 @@ lilv_state_save(LilvWorld* world,
}
// FIXME: make parameter non-const?
+ if (state->dir) {
+ free(state->dir);
+ }
((LilvState*)state)->dir = lilv_strdup(dir);
char* const manifest = lilv_path_join(dir, "manifest.ttl");
@@ -922,10 +926,11 @@ lilv_state_save(LilvWorld* world,
i = zix_tree_iter_next(i)) {
const PathMap* pm = (const PathMap*)zix_tree_get(i);
- char* real_dir = lilv_strjoin(lilv_realpath(dir), "/", NULL);
+ char* real_dir = lilv_realpath(dir);
+ char* base = lilv_path_join(real_dir, NULL);
char* rel_path = lilv_path_join(dir, pm->rel);
char* target_path = lilv_path_is_child(pm->abs, state->file_dir)
- ? lilv_path_relative_to(pm->abs, real_dir)
+ ? lilv_path_relative_to(pm->abs, base)
: lilv_strdup(pm->abs);
if (lilv_symlink(target_path, rel_path)) {
LILV_ERRORF("Failed to link `%s' => `%s' (%s)\n",
@@ -933,6 +938,8 @@ lilv_state_save(LilvWorld* world,
}
free(target_path);
free(rel_path);
+ free(base);
+ free(real_dir);
}
#endif
@@ -1019,6 +1026,8 @@ lilv_state_save(LilvWorld* world,
free(default_dir);
free(default_filename);
+ free(manifest);
+ free(path);
return 0;
}
diff --git a/src/util.c b/src/util.c
index a693d2d..47846da 100644
--- a/src/util.c
+++ b/src/util.c
@@ -170,7 +170,7 @@ lilv_expand(const char* path)
if (*s == '$') {
// Hit $ (variable reference, e.g. $VAR_NAME)
for (const char* t = s + 1; ; ++t) {
- if (!*t || !isupper(*t) || !isdigit(*t) || *t != '_') {
+ if (!*t || (!isupper(*t) && !isdigit(*t) && *t != '_')) {
// Append preceding chunk
out = strappend(out, &len, start, s - start);
@@ -309,14 +309,16 @@ char*
lilv_path_join(const char* a, const char* b)
{
const size_t a_len = strlen(a);
- const size_t b_len = strlen(b);
+ const size_t b_len = b ? strlen(b) : 0;
const size_t pre_len = a_len - (lilv_is_dir_sep(a[a_len - 1]) ? 1 : 0);
char* path = (char*)calloc(1, a_len + b_len + 2);
memcpy(path, a, pre_len);
path[pre_len] = LILV_DIR_SEP[0];
- memcpy(path + pre_len + 1,
- b + (lilv_is_dir_sep(b[0]) ? 1 : 0),
- lilv_is_dir_sep(b[0]) ? b_len - 1 : b_len);
+ if (b) {
+ memcpy(path + pre_len + 1,
+ b + (lilv_is_dir_sep(b[0]) ? 1 : 0),
+ lilv_is_dir_sep(b[0]) ? b_len - 1 : b_len);
+ }
return path;
}
@@ -371,6 +373,7 @@ lilv_get_latest_copy(const char* path)
lilv_dir_for_each(dirname, &latest, update_latest);
free(latest.pattern);
+ free(dirname);
return latest.latest;
}
diff --git a/test/lilv_test.c b/test/lilv_test.c
index 1a02889..3e497e6 100644
--- a/test/lilv_test.c
+++ b/test/lilv_test.c
@@ -1116,7 +1116,7 @@ char*
lilv_make_path(LV2_State_Make_Path_Handle handle,
const char* path)
{
- return lilv_strjoin(file_dir, "/", path, NULL);
+ return lilv_path_join(file_dir, path);
}
int
@@ -1319,6 +1319,9 @@ test_state(void)
lilv_state_free(fstate3);
lilv_state_free(fstate4);
lilv_state_free(fstate5);
+ lilv_state_free(fstate6);
+ lilv_state_free(fstate7);
+ lilv_state_free(fstate72);
// Free URI map
for (size_t i = 0; i < n_uris; ++i) {
@@ -1404,30 +1407,31 @@ test_string(void)
{
char* s = NULL;
- TEST_ASSERT(!strcmp((s = lilv_dirname("/foo/bar")), "/foo"));
- TEST_ASSERT(!strcmp((s = lilv_dirname("/foo/bar/")), "/foo"));
- TEST_ASSERT(!strcmp((s = lilv_dirname("/foo///bar/")), "/foo"));
- TEST_ASSERT(!strcmp((s = lilv_dirname("/foo///bar//")), "/foo"));
- TEST_ASSERT(!strcmp((s = lilv_dirname("foo")), "."));
- TEST_ASSERT(!strcmp((s = lilv_dirname("/foo")), "/"));
- TEST_ASSERT(!strcmp((s = lilv_dirname("/")), "/"));
- TEST_ASSERT(!strcmp((s = lilv_dirname("//")), "/"));
- TEST_ASSERT(!strcmp((s = lilv_path_relative_to("/a/b", "/a/")), "b"));
- TEST_ASSERT(!strcmp((s = lilv_path_relative_to("/a", "/b/c/")), "/a"));
- TEST_ASSERT(!strcmp((s = lilv_path_relative_to("/a/b/c", "/a/b/d/")), "../c"));
- TEST_ASSERT(!strcmp((s = lilv_path_relative_to("/a/b/c", "/a/b/d/e/")), "../../c"));
- TEST_ASSERT(!strcmp((s = lilv_path_join("/a", "b")), "/a/b"));
- TEST_ASSERT(!strcmp((s = lilv_path_join("/a", "/b")), "/a/b"));
- TEST_ASSERT(!strcmp((s = lilv_path_join("/a/", "/b")), "/a/b"));
- TEST_ASSERT(!strcmp((s = lilv_path_join("/a/", "b")), "/a/b"));
+ TEST_ASSERT(!strcmp((s = lilv_dirname("/foo/bar")), "/foo")); free(s);
+ TEST_ASSERT(!strcmp((s = lilv_dirname("/foo/bar/")), "/foo")); free(s);
+ TEST_ASSERT(!strcmp((s = lilv_dirname("/foo///bar/")), "/foo")); free(s);
+ TEST_ASSERT(!strcmp((s = lilv_dirname("/foo///bar//")), "/foo")); free(s);
+ TEST_ASSERT(!strcmp((s = lilv_dirname("foo")), ".")); free(s);
+ TEST_ASSERT(!strcmp((s = lilv_dirname("/foo")), "/")); free(s);
+ TEST_ASSERT(!strcmp((s = lilv_dirname("/")), "/")); free(s);
+ TEST_ASSERT(!strcmp((s = lilv_dirname("//")), "/")); free(s);
+ TEST_ASSERT(!strcmp((s = lilv_path_relative_to("/a/b", "/a/")), "b")); free(s);
+ TEST_ASSERT(!strcmp((s = lilv_path_relative_to("/a", "/b/c/")), "/a")); free(s);
+ TEST_ASSERT(!strcmp((s = lilv_path_relative_to("/a/b/c", "/a/b/d/")), "../c")); free(s);
+ TEST_ASSERT(!strcmp((s = lilv_path_relative_to("/a/b/c", "/a/b/d/e/")), "../../c")); free(s);
+ TEST_ASSERT(!strcmp((s = lilv_path_join("/a", "b")), "/a/b")); free(s);
+ TEST_ASSERT(!strcmp((s = lilv_path_join("/a", "/b")), "/a/b")); free(s);
+ TEST_ASSERT(!strcmp((s = lilv_path_join("/a/", "/b")), "/a/b")); free(s);
+ TEST_ASSERT(!strcmp((s = lilv_path_join("/a/", "b")), "/a/b")); free(s);
+ TEST_ASSERT(!strcmp((s = lilv_path_join("/a", NULL)), "/a/")); free(s);
setenv("LILV_TEST_1", "test", 1);
char* home_foo = lilv_strjoin(getenv("HOME"), "/foo", NULL);
- TEST_ASSERT(!strcmp((s = lilv_expand("$LILV_TEST_1")), "test"));
- TEST_ASSERT(!strcmp((s = lilv_expand("~")), getenv("HOME")));
- TEST_ASSERT(!strcmp((s = lilv_expand("~foo")), "~foo"));
- TEST_ASSERT(!strcmp((s = lilv_expand("~/foo")), home_foo));
- TEST_ASSERT(!strcmp((s = lilv_expand("$NOT_A_VAR")), "$NOT_A_VAR"));
+ TEST_ASSERT(!strcmp((s = lilv_expand("$LILV_TEST_1")), "test")); free(s);
+ TEST_ASSERT(!strcmp((s = lilv_expand("~")), getenv("HOME"))); free(s);
+ TEST_ASSERT(!strcmp((s = lilv_expand("~foo")), "~foo")); free(s);
+ TEST_ASSERT(!strcmp((s = lilv_expand("~/foo")), home_foo)); free(s);
+ TEST_ASSERT(!strcmp((s = lilv_expand("$NOT_A_VAR")), "$NOT_A_VAR")); free(s);
free(home_foo);
unsetenv("LILV_TEST_1");
diff --git a/test/test_plugin.c b/test/test_plugin.c
index 55df26c..ef66863 100644
--- a/test/test_plugin.c
+++ b/test/test_plugin.c
@@ -58,6 +58,8 @@ cleanup(LV2_Handle instance)
if (test->rec_file) {
fclose(test->rec_file);
}
+ free(test->tmp_file_path);
+ free(test->rec_file_path);
free(instance);
}
@@ -124,7 +126,6 @@ instantiate(const LV2_Descriptor* descriptor,
fprintf(stderr, "ERROR: Failed to open rec file\n");
}
fprintf(test->rec_file, "instantiate\n");
-
}
return (LV2_Handle)test;
@@ -300,6 +301,8 @@ restore(LV2_Handle instance,
fprintf(stderr, "ERROR: Restored bad path `%s' != `%s'\n",
real_path, plugin->tmp_file_path);
}
+ free(real_path);
+ free(path);
}
}