diff mbox

[U-Boot,03/10] ext4: free allocations by parse_path()

Message ID 1441425831-3441-3-git-send-email-swarren@wwwdotorg.org
State Accepted
Delegated to: Tom Rini
Headers show

Commit Message

Stephen Warren Sept. 5, 2015, 4:03 a.m. UTC
From: Stephen Warren <swarren@nvidia.com>

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 <swarren@nvidia.com>
---
 fs/ext4/ext4_common.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Comments

Ɓukasz Majewski Sept. 8, 2015, 1:10 p.m. UTC | #1
Hi Stephen,

> From: Stephen Warren <swarren@nvidia.com>
> 
> 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 <swarren@nvidia.com>
> ---
>  fs/ext4/ext4_common.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/ext4/ext4_common.c b/fs/ext4/ext4_common.c
> index cab5465b9d4f..b09f23aa5b83 100644
> --- a/fs/ext4/ext4_common.c
> +++ b/fs/ext4/ext4_common.c
> @@ -614,8 +614,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) {
> @@ -745,6 +744,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);

Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>

Test HW: Odroid XU3 - Exynos5433
[DFU tests]
Tom Rini Sept. 12, 2015, 12:51 p.m. UTC | #2
On Fri, Sep 04, 2015 at 10:03:44PM -0600, Stephen Warren wrote:

> From: Stephen Warren <swarren@nvidia.com>
> 
> 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 <swarren@nvidia.com>
> Acked-by: Lukasz Majewski <l.majewski@samsung.com>
> Tested-by: Lukasz Majewski <l.majewski@samsung.com>

Applied to u-boot/master, thanks!
diff mbox

Patch

diff --git a/fs/ext4/ext4_common.c b/fs/ext4/ext4_common.c
index cab5465b9d4f..b09f23aa5b83 100644
--- a/fs/ext4/ext4_common.c
+++ b/fs/ext4/ext4_common.c
@@ -614,8 +614,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) {
@@ -745,6 +744,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);