mirror of
				https://xff.cz/git/u-boot/
				synced 2025-10-31 18:35:42 +01:00 
			
		
		
		
	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 <swarren@nvidia.com> Acked-by: Lukasz Majewski <l.majewski@samsung.com> Tested-by: Lukasz Majewski <l.majewski@samsung.com>
This commit is contained in:
		| @@ -615,8 +615,7 @@ static int parse_path(char **arr, char *dirname) | |||||||
| 	arr[i] = zalloc(strlen("/") + 1); | 	arr[i] = zalloc(strlen("/") + 1); | ||||||
| 	if (!arr[i]) | 	if (!arr[i]) | ||||||
| 		return -ENOMEM; | 		return -ENOMEM; | ||||||
|  | 	memcpy(arr[i++], "/", strlen("/")); | ||||||
| 	arr[i++] = "/"; |  | ||||||
|  |  | ||||||
| 	/* add each path entry after root */ | 	/* add each path entry after root */ | ||||||
| 	while (token != NULL) { | 	while (token != NULL) { | ||||||
| @@ -746,6 +745,11 @@ end: | |||||||
| fail: | fail: | ||||||
| 	free(depth_dirname); | 	free(depth_dirname); | ||||||
| 	free(parse_dirname); | 	free(parse_dirname); | ||||||
|  | 	for (i = 0; i < depth; i++) { | ||||||
|  | 		if (!ptr[i]) | ||||||
|  | 			break; | ||||||
|  | 		free(ptr[i]); | ||||||
|  | 	} | ||||||
| 	free(ptr); | 	free(ptr); | ||||||
| 	free(parent_inode); | 	free(parent_inode); | ||||||
| 	free(first_inode); | 	free(first_inode); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user