[libvirt] [PATCH libvirt-python 06/17] Remove use of VIR_FREE from code

Eric Blake eblake at redhat.com
Mon Sep 9 17:20:37 UTC 2013


On 09/09/2013 10:01 AM, Daniel P. Berrange wrote:
> From: "Daniel P. Berrange" <berrange at redhat.com>
> 
> We don't have access to the libvirt memory APIs to replace

s/to replace/so replace/

> VIR_FREE with free().
> 
> Signed-off-by: Daniel P. Berrange <berrange at redhat.com>
> ---
>  libvirt-lxc-override.c  |   4 +-
>  libvirt-override.c      | 228 ++++++++++++++++++++++++------------------------
>  libvirt-qemu-override.c |   4 +-
>  typewrappers.c          |   4 +-
>  4 files changed, 120 insertions(+), 120 deletions(-)

Most of your conversions occur right before a variable goes out of
scope, and are therefore safe.  However...

> @@ -2482,13 +2482,13 @@ libvirt_virDomainSnapshotListNames(PyObject *self,
>              py_retval = NULL;
>              goto cleanup;
>          }
> -        VIR_FREE(names[i]);
> +        free(names[i]);
>      }
>  
>  cleanup:
>      for (i = 0; i < c_retval; i++)
> -        VIR_FREE(names[i]);
> -    VIR_FREE(names);
> +        free(names[i]);

Ouch - double free.  VIR_FREE(names[i]) set names[i] to NULL, so that
even if we abort early, the cleanup will fix the remaining array entries
without choking on the already freed entries in the first half of the
array.  But with your rewrite, since you fail to set to NULL, an early
abort will call free(names[0]) twice if we fail during the i==1 iteration.

> @@ -2583,13 +2583,13 @@ libvirt_virDomainSnapshotListChildrenNames(PyObject *self,
>              py_retval = NULL;
>              goto cleanup;
>          }
> -        VIR_FREE(names[i]);
> +        free(names[i]);
>      }
>  
>  cleanup:
>      for (i = 0; i < c_retval; i++)
> -        VIR_FREE(names[i]);
> -    VIR_FREE(names);
> +        free(names[i]);

and again.

-- 
Eric Blake   eblake 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: 621 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20130909/dd800195/attachment-0001.sig>


More information about the libvir-list mailing list