debuggers.hg

changeset 22764:ee3a97548604

libxl: do not leak front flexarray on error in libxl_create_pci_backend

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
author Ian Campbell <ian.campbell@citrix.com>
date Tue Jan 11 18:15:38 2011 +0000 (2011-01-11)
parents 76ad4bb4c583
children fd6239cbac00
files tools/libxl/libxl_pci.c
line diff
     1.1 --- a/tools/libxl/libxl_pci.c	Tue Jan 11 18:15:18 2011 +0000
     1.2 +++ b/tools/libxl/libxl_pci.c	Tue Jan 11 18:15:38 2011 +0000
     1.3 @@ -224,17 +224,19 @@ parse_error:
     1.4  static int libxl_create_pci_backend(libxl__gc *gc, uint32_t domid, libxl_device_pci *pcidev, int num)
     1.5  {
     1.6      libxl_ctx *ctx = libxl__gc_owner(gc);
     1.7 -    flexarray_t *front;
     1.8 -    flexarray_t *back;
     1.9 +    flexarray_t *front = NULL;
    1.10 +    flexarray_t *back = NULL;
    1.11      libxl__device device;
    1.12 -    int i;
    1.13 +    int ret = ERROR_NOMEM, i;
    1.14  
    1.15      front = flexarray_make(16, 1);
    1.16      if (!front)
    1.17 -        return ERROR_NOMEM;
    1.18 +        goto out;
    1.19      back = flexarray_make(16, 1);
    1.20      if (!back)
    1.21 -        return ERROR_NOMEM;
    1.22 +        goto out;
    1.23 +
    1.24 +    ret = 0;
    1.25  
    1.26      LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "Creating pci backend");
    1.27  
    1.28 @@ -271,8 +273,11 @@ static int libxl_create_pci_backend(libx
    1.29                               libxl__xs_kvs_of_flexarray(gc, back, back->count),
    1.30                               libxl__xs_kvs_of_flexarray(gc, front, front->count));
    1.31  
    1.32 -    flexarray_free(back);
    1.33 -    flexarray_free(front);
    1.34 +out:
    1.35 +    if (back)
    1.36 +        flexarray_free(back);
    1.37 +    if (front)
    1.38 +        flexarray_free(front);
    1.39      return 0;
    1.40  }
    1.41