Wanlong Gao
2011-Dec-05 06:30 UTC
[Libguestfs] [PATCH] mdadm: fix a possible memory leak when error
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
Richard W.M. Jones
2011-Dec-05 08:59 UTC
[Libguestfs] [PATCH] mdadm: fix a possible memory leak when error
On Mon, Dec 05, 2011 at 02:30:35PM +0800, Wanlong Gao wrote:> 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;I'm not sure there's a problem. 'add_string' frees the strings and sets ret = NULL on error, so either way of doing this seems safe ... Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones New in Fedora 11: Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 70 libraries supprt'd http://fedoraproject.org/wiki/MinGW http://www.annexia.org/fedora_mingw
Maybe Matching Threads
- [PATCH] blkid: split the RHEL5 which can't support some options
- [PATCH] NEW API: add blkid command to print the attributes of the device
- [PATCH 1/3] NEW API: add a new api zero_fs
- [PATCH] New API: mdadm-stop for stopping MD devices.
- [PATCH 00/14] Run the daemon under valgrind and fix resultant errors.