diff options
author | Jeremy Kerr <jk@ozlabs.org> | 2013-11-14 16:18:59 +1100 |
---|---|---|
committer | Jeremy Kerr <jk@ozlabs.org> | 2013-11-14 16:18:59 +1100 |
commit | 89f43bf771edf352479f26395b56594201f0d958 (patch) | |
tree | 2edf3d4ce07f85cfa012d1c7a943b5f97732bf39 /lib | |
parent | 8c8fd93738a5d589b52a3791cd231e6661322b76 (diff) | |
download | talos-petitboot-89f43bf771edf352479f26395b56594201f0d958.tar.gz talos-petitboot-89f43bf771edf352479f26395b56594201f0d958.zip |
lib/system: Don't leak in pb_mkdir_recursive
If the mkdir fails, we'll exit without freeing str.
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/system/system.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/system/system.c b/lib/system/system.c index 0253ac8..917d444 100644 --- a/lib/system/system.c +++ b/lib/system/system.c @@ -39,8 +39,8 @@ enum tftp_type tftp_type = TFTP_TYPE; int pb_mkdir_recursive(const char *dir) { struct stat statbuf; + int rc, mode = 0755; char *str, *sep; - int mode = 0755; if (!*dir) return 0; @@ -57,6 +57,8 @@ int pb_mkdir_recursive(const char *dir) str = talloc_strdup(NULL, dir); sep = strchr(*str == '/' ? str + 1 : str, '/'); + rc = 0; + while (1) { /* terminate the path at sep */ @@ -65,7 +67,8 @@ int pb_mkdir_recursive(const char *dir) if (mkdir(str, mode) && errno != EEXIST) { pb_log("mkdir(%s): %s\n", str, strerror(errno)); - return -1; + rc = -1; + break; } if (!sep) @@ -78,7 +81,7 @@ int pb_mkdir_recursive(const char *dir) talloc_free(str); - return 0; + return rc; } int pb_rmdir_recursive(const char *base, const char *dir) |