Skip to contentSkip to conversation

fs: ext4: Fix free(NULL) The 'depth_dirname', 'ptr', 'parent_inode' and 'first_inode' pointers may be null. Thus, it is necessary to check them before using free() to avoid free(NULL) cases.

PATCH In review Mikhail Ilin 2 participants 2 messages Nov 22, 2022 – Dec 8, 2022 ext4 file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs: ext4: Fix free(NULL) The 'depth_dirname', 'ptr', 'parent_inode' and 'first_inode' pointers may be null. Thus, it is necessary to check them before using free() to avoid free(NULL) cases.

Fixes 934b14f2bb30 ("ext4: free allocations by parse_path()")
---
 fs/ext4/ext4_common.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)
fs/ext4/ext4_common.c +13 -8
index 5bf78b530a..422497c257 100644
@@ -847,15 +847,20 @@ end:
 
 fail:
 	free(depth_dirname);
-	free(parse_dirname);
-	for (i = 0; i < depth; i++) {
-		if (!ptr[i])
-			break;
-		free(ptr[i]);
+	if (parse_dirname)
+		free(parse_dirname);
+	if (ptr) {
+		for (i = 0; i < depth; i++) {
+			if (!ptr[i])
+				break;
+			free(ptr[i]);
+		}
+		free(ptr);
 	}
-	free(ptr);
-	free(parent_inode);
-	free(first_inode);
+	if (parent_inode)
+		free(parent_inode);
+	if (first_inode)
+		free(first_inode);
 
 	return result_inode_no;
 }
Signature · 1 line
2.17.1