]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
utils: lxc_deslashify() free memory 1212/head
authorChristian Brauner <christian.brauner@canonical.com>
Mon, 26 Sep 2016 20:05:54 +0000 (22:05 +0200)
committerChristian Brauner <christian.brauner@canonical.com>
Mon, 26 Sep 2016 20:42:52 +0000 (22:42 +0200)
Make sure we always free any memory that was allocated by the call to
lxc_normalize_path().

Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
src/lxc/utils.c

index ebf3ad981d501bd06e8932932ea7ba709a6b1f30..2029e3328b2f21725adfd72299b57bb0b90e98e7 100644 (file)
@@ -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)