summaryrefslogtreecommitdiffstats
path: root/src/util.c
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 /src/util.c
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
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c13
1 files changed, 8 insertions, 5 deletions
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;
}