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

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

 



On 11/29/2011 10:57 PM, ajia@xxxxxxxxxx wrote:
> From: Alex Jia <ajia@xxxxxxxxxx>
> 
> Detected by Coverity. Leak introduced in commit c1df2c1.
> 
> Signed-off-by: Alex Jia <ajia@xxxxxxxxxx>
> ---
>  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@xxxxxxxxxx    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]