Re: [PATCH 03/14] storage: Resolve resource leak using 'vol' buffer

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

 



On 01/09/2013 07:54 AM, John Ferlan wrote:
> ---
>  src/storage/storage_backend_rbd.c | 13 ++++++++++---
>  1 file changed, 10 insertions(+), 3 deletions(-)
> 

>          vol->name = strdup(name);
> -        if (vol->name == NULL)
> +        if (vol->name == NULL) {
> +            VIR_FREE(vol);
>              goto out_of_memory;
> +        }
>  
> -        if (STREQ(vol->name, ""))
> +        if (STREQ(vol->name, "")) {
> +            VIR_FREE(vol->name);
> +            VIR_FREE(vol);
>              break;
> +        }

It feels a bit awkward having to free more and more for each break.  I
rearranged the code slightly to hoist the validation prior to the
malloc.  ACK and pushed with this squashed in:

diff --git i/src/storage/storage_backend_rbd.c
w/src/storage/storage_backend_rbd.c
index f916de1..8a0e517 100644
--- i/src/storage/storage_backend_rbd.c
+++ w/src/storage/storage_backend_rbd.c
@@ -1,6 +1,7 @@
 /*
  * storage_backend_rbd.c: storage backend for RBD (RADOS Block Device)
handling
  *
+ * Copyright (C) 2013 Red Hat, Inc.
  * Copyright (C) 2012 Wido den Hollander
  *
  * This library is free software; you can redistribute it and/or
@@ -319,12 +320,16 @@ static int
virStorageBackendRBDRefreshPool(virConnectPtr conn ATTRIBUTE_UNUSED,
     }

     for (i = 0, name = names; name < names + max_size; i++) {
+        virStorageVolDefPtr vol;
+
         if (VIR_REALLOC_N(pool->volumes.objs, pool->volumes.count + 1)
< 0) {
             virStoragePoolObjClearVols(pool);
             goto out_of_memory;
         }

-        virStorageVolDefPtr vol;
+        if (STREQ(name, ""))
+            break;
+
         if (VIR_ALLOC(vol) < 0)
             goto out_of_memory;

@@ -334,12 +339,6 @@ static int
virStorageBackendRBDRefreshPool(virConnectPtr conn ATTRIBUTE_UNUSED,
             goto out_of_memory;
         }

-        if (STREQ(vol->name, "")) {
-            VIR_FREE(vol->name);
-            VIR_FREE(vol);
-            break;
-        }
-
         name += strlen(name) + 1;

         if (volStorageBackendRBDRefreshVolInfo(vol, pool, ptr) < 0) {


-- 
Eric Blake   eblake redhat com    +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]