diff mbox series

xfsdump: fix memory leak

Message ID 66a008ab-b54a-6f72-727c-efce8654b481@huawei.com (mailing list archive)
State Deferred, archived
Headers show
Series xfsdump: fix memory leak | expand

Commit Message

zhanchengbin Sept. 22, 2022, 3:02 a.m. UTC
Need free tmphdr and newnode before return,
otherwise it will cause memory leak.

Signed-off-by: zhanchengbin <zhanchengbin1@huawei.com>
---
  common/drive_simple.c | 1 +
  invutil/list.c        | 4 +++-
  2 files changed, 4 insertions(+), 1 deletion(-)

      newdata->expanded = expanded;
diff mbox series

Patch

diff --git a/common/drive_simple.c b/common/drive_simple.c
index 5c3ed4b..141fdcb 100644
--- a/common/drive_simple.c
+++ b/common/drive_simple.c
@@ -456,6 +456,7 @@  do_begin_read(drive_t *drivep)
  	/* can only read one media file
  	 */
  	if (contextp->dc_fmarkcnt > 0) {
+		free(tmphdr);
  		return DRIVE_ERROR_EOM;
  	}

diff --git a/invutil/list.c b/invutil/list.c
index 46fb291..a3a4cfd 100644
--- a/invutil/list.c
+++ b/invutil/list.c
@@ -52,8 +52,10 @@  node_create(int hidden, int expanded, int level, int 
deleted, int file_idx, char
  	return NULL;

      newdata = malloc(sizeof(*newdata));
-    if(newdata == NULL)
+    if(newdata == NULL) {
+	free(newnode);
  	return NULL;
+    }

      newdata->hidden = hidden;