Commit f9f676d7 by Christian Brauner Committed by Stéphane Graber

utils: lxc_deslashify() free memory

Make sure we always free any memory that was allocated by the call to lxc_normalize_path(). Signed-off-by: 's avatarChristian Brauner <christian.brauner@canonical.com>
parent 3d5658d1
......@@ -718,6 +718,7 @@ char **lxc_normalize_path(const char *path)
bool lxc_deslashify(char **path)
{
bool ret = false;
char *p;
char **parts = NULL;
size_t n, len;
......@@ -729,28 +730,33 @@ bool lxc_deslashify(char **path)
/* We'll end up here if path == "///" or path == "". */
if (!*parts) {
len = strlen(*path);
if (!len)
return true;
if (!len) {
ret = true;
goto out;
}
n = strcspn(*path, "/");
if (n == len) {
p = strdup("/");
if (!p)
return false;
goto out;
free(*path);
*path = p;
return true;
ret = true;
goto out;
}
}
p = lxc_string_join("/", (const char **)parts, **path == '/');
lxc_free_array((void **)parts, free);
if (!p)
return false;
goto out;
free(*path);
*path = p;
ret = true;
return true;
out:
lxc_free_array((void **)parts, free);
return ret;
}
char *lxc_append_paths(const char *first, const char *second)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment