[libvirt] [PATCH 5/6] util: Plug memory leak on virNetDevBridgeGet() sucessful path

Eric Blake eblake at redhat.com
Wed Nov 30 23:46:47 UTC 2011


On 11/29/2011 10:57 PM, ajia at redhat.com wrote:
> From: Alex Jia <ajia at redhat.com>
> 
> Detected by Coverity. Leak introduced in commit c1df2c1.
> 
> Signed-off-by: Alex Jia <ajia at redhat.com>
> ---
>  src/util/virnetdevbridge.c |    1 +
>  1 files changed, 1 insertions(+), 0 deletions(-)
> 
> diff --git a/src/util/virnetdevbridge.c b/src/util/virnetdevbridge.c
> index 060445d..d9708fa 100644
> --- a/src/util/virnetdevbridge.c
> +++ b/src/util/virnetdevbridge.c
> @@ -168,6 +168,7 @@ static int virNetDevBridgeGet(const char *brname,
>              virReportSystemError(EINVAL,
>                                   _("Unable to get bridge %s %s"), brname, paramname);
>          }
> +        VIR_FREE(valuestr);

An improvement, but still not quite right.  If we reported EINVAL, we
lacked the goto cleanup that let this function return -1.

Pushing with this squashed in:

diff --git i/src/util/virnetdevbridge.c w/src/util/virnetdevbridge.c
index d9708fa..0440a73 100644
--- i/src/util/virnetdevbridge.c
+++ w/src/util/virnetdevbridge.c
@@ -161,12 +161,16 @@ static int virNetDevBridgeGet(const char *brname,

     if (virFileExists(path)) {
         char *valuestr;
-        if (virFileReadAll(path, INT_BUFSIZE_BOUND(unsigned long),
&valuestr) < 0)
+        if (virFileReadAll(path, INT_BUFSIZE_BOUND(unsigned long),
+                           &valuestr) < 0)
             goto cleanup;

         if (virStrToLong_ul(valuestr, NULL, 10, value) < 0) {
             virReportSystemError(EINVAL,
-                                 _("Unable to get bridge %s %s"),
brname, paramname);
+                                 _("Unable to get bridge %s %s"),
+                                 brname, paramname);
+            VIR_FREE(valuestr);
+            goto cleanup;
         }
         VIR_FREE(valuestr);
     } else {


-- 
Eric Blake   eblake at redhat.com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 620 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20111130/3996d2d8/attachment-0001.sig>


More information about the libvir-list mailing list