[Libguestfs] [PATCH] mdadm: fix a possible memory leak when error

Wanlong Gao gaowanlong at cn.fujitsu.com
Mon Dec 5 06:30:35 UTC 2011


When add_string() error, it returned without free the *ret*.

Signed-off-by: Wanlong Gao <gaowanlong at cn.fujitsu.com>
---
 daemon/md.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/daemon/md.c b/daemon/md.c
index 5a4d815..8d28878 100644
--- a/daemon/md.c
+++ b/daemon/md.c
@@ -294,12 +294,12 @@ do_md_detail(const char *md)
     }
   }
 
+  if (add_string(&ret, &size, &alloc, NULL) == -1) goto error;
+
   free(out);
   free(err);
   free(lines); /* We freed the contained strings when we freed out */
 
-  if (add_string(&ret, &size, &alloc, NULL) == -1) return NULL;
-
   return ret;
 
 error:
-- 
1.7.8.rc4




More information about the Libguestfs mailing list