From: Stephen Warren Date: Sat, 5 Sep 2015 04:03:44 +0000 (-0600) Subject: ext4: free allocations by parse_path() X-Git-Tag: v2015.10-rc4~116 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=934b14f2bb306dfa1947d30f4df90cdc8b710332;p=oweals%2Fu-boot.git ext4: free allocations by parse_path() parse_path() malloc()s the entries in the array it's passed. Those allocations must be free()d by the caller, ext4fs_get_parent_inode_num(). Add code to do this. For this to work, all the array entries must be dynamically allocated, rather than a mix of dynamic and static allocations. Fix parse_path() not to over-write arr[0] with a pointer to statically allocated data. Signed-off-by: Stephen Warren Acked-by: Lukasz Majewski Tested-by: Lukasz Majewski --- diff --git a/fs/ext4/ext4_common.c b/fs/ext4/ext4_common.c index c77e22d477..9fdbfe6e2d 100644 --- a/fs/ext4/ext4_common.c +++ b/fs/ext4/ext4_common.c @@ -615,8 +615,7 @@ static int parse_path(char **arr, char *dirname) arr[i] = zalloc(strlen("/") + 1); if (!arr[i]) return -ENOMEM; - - arr[i++] = "/"; + memcpy(arr[i++], "/", strlen("/")); /* add each path entry after root */ while (token != NULL) { @@ -746,6 +745,11 @@ end: fail: free(depth_dirname); free(parse_dirname); + for (i = 0; i < depth; i++) { + if (!ptr[i]) + break; + free(ptr[i]); + } free(ptr); free(parent_inode); free(first_inode);