]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
unit-name: fix memory leak
authorDaniel Mack <daniel@zonque.org>
Thu, 30 Jul 2015 13:51:50 +0000 (15:51 +0200)
committerDaniel Mack <daniel@zonque.org>
Thu, 30 Jul 2015 13:51:50 +0000 (15:51 +0200)
Fix a memory leak introduced by 2fc09a9c. 's' is used twice in this
function, and if free_and_strdup() fails, the pointer is left untouched.

src/basic/unit-name.c

index 4b84542d0c40f5eba346c97bd45e07a0d0edba8c..fa530da456b5fe9785cbcd3dca9e71a482bce26c 100644 (file)
@@ -695,8 +695,10 @@ int slice_build_parent_slice(const char *slice, char **ret) {
                 strcpy(dash, ".slice");
         else {
                 r = free_and_strdup(&s, "-.slice");
-                if (r < 0)
+                if (r < 0) {
+                        free(s);
                         return r;
+                }
         }
 
         *ret = s;