debuggers.hg

changeset 22086:597da2edfe30

libxl/xl: use libxl_diskinfo_destroy and libxl_device_disk_destroy

[PATCH 13 of 16 of
libxl: autogenerate type definitions and destructor functions]

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
author Ian Campbell <ian.campbell@citrix.com>
date Thu Aug 19 15:31:46 2010 +0100 (2010-08-19)
parents dc381437e19d
children 4c9ef5ec9146
files tools/libxl/libxl.c tools/libxl/xl_cmdimpl.c
line diff
     1.1 --- a/tools/libxl/libxl.c	Thu Aug 19 15:31:14 2010 +0100
     1.2 +++ b/tools/libxl/libxl.c	Thu Aug 19 15:31:46 2010 +0100
     1.3 @@ -1355,8 +1355,8 @@ static char ** libxl_build_device_model_
     1.4              flexarray_set(dm_args, num++, libxl_sprintf(gc, "-%s", disks[i].virtpath));
     1.5              flexarray_set(dm_args, num++, disks[i].physpath);
     1.6          }
     1.7 +        libxl_device_disk_destroy(&disks[i]);
     1.8      }
     1.9 -    /* FIXME: leaks disk paths */
    1.10      free(disks);
    1.11      flexarray_set(dm_args, num++, NULL);
    1.12      return (char **) flexarray_contents(dm_args);
    1.13 @@ -2562,6 +2562,7 @@ int libxl_cdrom_insert(libxl_ctx *ctx, u
    1.14      int num, i;
    1.15      uint32_t stubdomid;
    1.16      libxl_device_disk *disks;
    1.17 +    int ret = ERROR_FAIL;
    1.18  
    1.19      if (!disk->physpath) {
    1.20          disk->physpath = "";
    1.21 @@ -2575,9 +2576,11 @@ int libxl_cdrom_insert(libxl_ctx *ctx, u
    1.22      }
    1.23      if (i == num) {
    1.24          XL_LOG(ctx, XL_LOG_ERROR, "Virtual device not found");
    1.25 -        free(disks);
    1.26 -        return ERROR_FAIL;
    1.27 +        goto out;
    1.28      }
    1.29 +
    1.30 +    ret = 0;
    1.31 +
    1.32      libxl_device_disk_del(ctx, disks + i, 1);
    1.33      libxl_device_disk_add(ctx, domid, disk);
    1.34      stubdomid = libxl_get_stubdom_id(ctx, domid);
    1.35 @@ -2588,9 +2591,11 @@ int libxl_cdrom_insert(libxl_ctx *ctx, u
    1.36          libxl_device_disk_add(ctx, stubdomid, disk);
    1.37          disk->domid = domid;
    1.38      }
    1.39 -    /* FIXME: leaks disk paths */
    1.40 +out:
    1.41 +    for (i = 0; i < num; i++)
    1.42 +        libxl_device_disk_destroy(&disks[i]);
    1.43      free(disks);
    1.44 -    return 0;
    1.45 +    return ret;
    1.46  }
    1.47  
    1.48  /******************************************************************************/
     2.1 --- a/tools/libxl/xl_cmdimpl.c	Thu Aug 19 15:31:14 2010 +0100
     2.2 +++ b/tools/libxl/xl_cmdimpl.c	Thu Aug 19 15:31:46 2010 +0100
     2.3 @@ -4261,7 +4261,7 @@ int main_blockattach(int argc, char **ar
     2.4  int main_blocklist(int argc, char **argv)
     2.5  {
     2.6      int opt;
     2.7 -    int nb;
     2.8 +    int i, nb;
     2.9      libxl_device_disk *disks;
    2.10      libxl_diskinfo diskinfo;
    2.11  
    2.12 @@ -4291,14 +4291,17 @@ int main_blocklist(int argc, char **argv
    2.13          if (!disks) {
    2.14              continue;
    2.15          }
    2.16 -        for (; nb > 0; --nb, ++disks) {
    2.17 -            if (!libxl_device_disk_getinfo(&ctx, domid, disks, &diskinfo)) {
    2.18 +        for (i=0; i<nb; i++) {
    2.19 +            if (!libxl_device_disk_getinfo(&ctx, domid, &disks[i], &diskinfo)) {
    2.20                  /*      Vdev BE   hdl  st   evch rref BE-path*/
    2.21                  printf("%-5d %-3d %-6d %-5d %-6d %-8d %-30s\n",
    2.22                         diskinfo.devid, diskinfo.backend_id, diskinfo.frontend_id,
    2.23                         diskinfo.state, diskinfo.evtch, diskinfo.rref, diskinfo.backend);
    2.24 +                libxl_diskinfo_destroy(&diskinfo);
    2.25              }
    2.26 +            libxl_device_disk_destroy(&disks[i]);
    2.27          }
    2.28 +        free(disks);
    2.29      }
    2.30      return 0;
    2.31  }