xfs
[Top] [All Lists]

[PATCH] xfsdump: Fix memory leak in invutil/stobj.c

To: xfs@xxxxxxxxxxx
Subject: [PATCH] xfsdump: Fix memory leak in invutil/stobj.c
From: Boris Ranto <ranto.boris@xxxxxxxxx>
Date: Wed, 5 Mar 2014 21:11:51 +0100
Cc: branto@xxxxxxxxxx, Boris Ranto <ranto.boris@xxxxxxxxx>
Delivered-to: xfs@xxxxxxxxxxx
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=XoAxX3FTgqzpxaLSsf0haGLZy3i6gGNcEK6IWcko4ks=; b=LaQox8Tmx2mjggzvNBjxdP1Si6fWVaNcZ1oxAGmcwEsWyJLr4uVLn0lAO0tAnEBNl3 5iGfQQW6H/LUqpfNh8ICJF6JBGpw/AgfRDspVMxc3Kh5bZg6UMi13hqMAW2yqqJumCay VYD+zCr3JUrg9tS4rPYaQozUWdOHB4fldO3kjurgnNbTH58+ZvJsqqtIVoQJgXc3iyQV 2fLP07r7/zxGg9+RFERyZnnjU38QSVVumX4Mq9Aw+UI1wbxBiu8HlH8L1UlowNNSmBwu Qo4Q7cITaFB0c6ZTxpeB6T/JjUYWZvlB23jJXE9WEoWW2BCTxPCQQWbckJQprX3J2iYR tgJw==
The function open_stobj duplicates its argument, upon successful
duplication, the fstat is called. If the fstat command fails then
the memory for the duplicated string is leaked. Fix this by moving
the string duplication after the fstat call. This is ok because
the fstat call does not use the duplicated string.

Signed-off-by: Boris Ranto <ranto.boris@xxxxxxxxx>
---
 invutil/stobj.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/invutil/stobj.c b/invutil/stobj.c
index 428b419..55abe63 100644
--- a/invutil/stobj.c
+++ b/invutil/stobj.c
@@ -578,12 +578,6 @@ open_stobj(char *StObjFileName)
        return fd;
     }
 
-    name = strdup(StObjFileName);
-    if(name == NULL) {
-       fprintf(stderr, "%s: internal memory error: strdup stobj_name\n", 
g_programName);
-       exit(1);
-    }
-
     read_n_bytes(fd, &cnt, sizeof(invt_sescounter_t), StObjFileName);
     lseek( fd, 0, SEEK_SET );
     errno = 0;
@@ -595,6 +589,12 @@ open_stobj(char *StObjFileName)
     size = sb.st_size;
     mapaddr = mmap_n_bytes(fd, size, BOOL_FALSE, StObjFileName);
 
+    name = strdup(StObjFileName);
+    if(name == NULL) {
+       fprintf(stderr, "%s: internal memory error: strdup stobj_name\n", 
g_programName);
+       exit(1);
+    }
+
     return add_stobj(name, fd, size, mapaddr, (invt_sescounter_t *)mapaddr);
 }
 
-- 
1.7.1

<Prev in Thread] Current Thread [Next in Thread>