[netcf-devel] [PATCH] debian: avoid a memory leak when listing interfaces

Serge E. Hallyn serge at hallyn.com
Tue Aug 13 19:33:32 UTC 2013


Quoting Eric Blake (eblake at redhat.com):
> Leak reported via Natanael Copa on IRC when used by libvirt:
> 
> ==623== 5,677,056 bytes in 693 blocks are definitely lost in loss record 3,354 of 3,358
> ==623== at 0x4C1138C: malloc (vg_replace_malloc.c:270)
> ==623== by 0x5B4A9F3: open_memstream (in /lib/libuClibc-0.9.33.2.so)
> ==623== by 0x5B485AF: vasprintf (in /lib/libuClibc-0.9.33.2.so)
> ==623== by 0x10BE7C8B: ???
> ==623== by 0x10BE7EE2: ???
> ==623== by 0x10BE8473: ???
> ==623== by 0x10BE8A53: ???
> ==623== by 0x109BD755: ???
> ==623== by 0x109BE47D: ???
> ==623== by 0x53450EF: virConnectListDefinedInterfaces (in /home/ncopa/aports/main/libvirt/src/libvirt-1.1.1/src/.libs/libvirt.so.0.1001.1)
> 
> Even without symbols, the lone call to vasprintf in drv_debian was
> a pretty blatant leak.

So, just to be sure - this hasn't been reported before, but it should
be applicable to every older version of netcf on debian, right?

> * src/drv_debian.c (interface_deps): Free path when done with it.
> 
> Signed-off-by: Eric Blake <eblake at redhat.com>
> ---
>  src/drv_debian.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/src/drv_debian.c b/src/drv_debian.c
> index d762a5d..370eccd 100644
> --- a/src/drv_debian.c
> +++ b/src/drv_debian.c
> @@ -140,16 +140,17 @@ static int interface_deps(struct netcf *ncf, char ***slaves, const char *fmt, ..
>      r = vasprintf(&path, fmt, args);
>      va_end(args);
>      if (r < 0) {
>          path = NULL;
>          ERR_NOMEM(1, ncf);
>      }
> 
>      nmatches = aug_match(aug, path, &matches);
> +    FREE(path);
>      ERR_COND_BAIL(nmatches < 0, ncf, EOTHER);
> 
>      if (!nmatches)
>          return 0;
> 
>      for (int i = 0 ; i < nmatches ; i++) {
>          r = aug_get(aug, matches[i], &devs);
>          ERR_COND_BAIL(r < 0, ncf, EOTHER);
> -- 
> 1.8.3.1
> 
> _______________________________________________
> netcf-devel mailing list
> netcf-devel at lists.fedorahosted.org
> https://lists.fedorahosted.org/mailman/listinfo/netcf-devel


More information about the netcf-devel mailing list