diff mbox series

[2/2] e2fsprogs: fix potential memory leak in path_append()

Message ID 20190115134203.11448-2-lczerner@redhat.com
State Accepted, archived
Headers show
Series [1/2] e2freefrag: fix memory leak in scan_online() | expand

Commit Message

Lukas Czerner Jan. 15, 2019, 1:42 p.m. UTC
If realloc() fails in path_append() we will lose a memory pointed to by
target->path. Fix it.

Signed-off-by: Lukas Czerner <lczerner@redhat.com>
---
 misc/create_inode.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Theodore Ts'o Feb. 11, 2019, 5:55 p.m. UTC | #1
On Tue, Jan 15, 2019 at 02:42:03PM +0100, Lukas Czerner wrote:
> If realloc() fails in path_append() we will lose a memory pointed to by
> target->path. Fix it.
> 
> Signed-off-by: Lukas Czerner <lczerner@redhat.com>

Thanks, applied.

					- Ted
diff mbox series

Patch

diff --git a/misc/create_inode.c b/misc/create_inode.c
index 05aa6363..cedbba52 100644
--- a/misc/create_inode.c
+++ b/misc/create_inode.c
@@ -704,10 +704,12 @@  struct file_info {
 static errcode_t path_append(struct file_info *target, const char *file)
 {
 	if (strlen(file) + target->path_len + 1 > target->path_max_len) {
+		void *p;
 		target->path_max_len *= 2;
-		target->path = realloc(target->path, target->path_max_len);
-		if (!target->path)
+		p = realloc(target->path, target->path_max_len);
+		if (p == NULL)
 			return EXT2_ET_NO_MEMORY;
+		target->path = p;
 	}
 	target->path_len += sprintf(target->path + target->path_len, "/%s",
 				    file);