[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [PATCH] nwfilter: fix memory leaks



2010/10/2 Stefan Berger <stefanb linux vnet ibm com>:
>  Fixing memory leak shown by valgrind and freeing buffer in two more places.
>
> Signed-off-by: Stefan Berger <stefanb us ibm com>
>
> Index: libvirt-acl/src/nwfilter/nwfilter_ebiptables_driver.c
> ===================================================================
> --- libvirt-acl.orig/src/nwfilter/nwfilter_ebiptables_driver.c
> +++ libvirt-acl/src/nwfilter/nwfilter_ebiptables_driver.c
> @@ -1508,7 +1508,11 @@ _iptablesCreateRuleInstance(int directio
>     }
>
>     if (virBufferUse(&prefix)) {
> -        virBufferVSprintf(&prefix, "%s", virBufferContentAndReset(&buf));
> +        char *s = virBufferContentAndReset(&buf);
> +
> +        virBufferVSprintf(&prefix, "%s", s);

You could simplify this to use virBufferAdd(&prefix, s, -1) instead of
virBufferVSprintf.

> +
> +        VIR_FREE(s);
>
>         final = &prefix;
>
> @@ -1531,11 +1535,13 @@ _iptablesCreateRuleInstance(int directio
>
>  err_exit:
>     virBufferFreeAndReset(&buf);
> +    virBufferFreeAndReset(&prefix);
>
>     return -1;
>
>  exit_no_error:
>     virBufferFreeAndReset(&buf);
> +    virBufferFreeAndReset(&prefix);
>
>     return 0;
>  }
>

ACK.

Matthias


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]