|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] [xen master] libxl: properly clean up array in libxl_list_cpupool failure path
commit c15bcbbcea383d1a1ac3c16cdea5ada4f26c5611
Author: Wei Liu <wei.liu2@xxxxxxxxxx>
AuthorDate: Mon Jul 27 18:45:02 2015 +0100
Commit: Ian Campbell <ian.campbell@xxxxxxxxxx>
CommitDate: Tue Jul 28 11:53:11 2015 +0100
libxl: properly clean up array in libxl_list_cpupool failure path
Document how cpupool_info works. Distinguish success (ERROR_FAIL +
ENOENT) vs failure in libxl_list_cpupool and properly clean up the array
in failure path.
Also switch to libxl__realloc and call libxl_cpupool_{init,dispose}
where appropriate.
There is change of behaviour. Previously if memory allocation fails the
said function returns NULL. Now memory allocation failure is fatal. This
is in line with how we deal with memory allocation failure in other
places in libxl though.
Signed-off-by: Wei Liu <wei.liu2@xxxxxxxxxx>
Reviewed-by: Dario Faggioli <dario.faggioli@xxxxxxxxxx>
Acked-by: Ian Campbell <ian.campbell@xxxxxxxxxx>
---
tools/libxl/libxl.c | 31 +++++++++++++++++++++----------
1 files changed, 21 insertions(+), 10 deletions(-)
diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index 614ca33..083f099 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -682,6 +682,11 @@ int libxl_domain_info(libxl_ctx *ctx, libxl_dominfo
*info_r,
return 0;
}
+/* Returns:
+ * 0 - success
+ * ERROR_FAIL + errno == ENOENT - no entry found
+ * ERROR_$FOO + errno != ENOENT - other failure
+ */
static int cpupool_info(libxl__gc *gc,
libxl_cpupoolinfo *info,
uint32_t poolid,
@@ -737,7 +742,8 @@ int libxl_cpupool_info(libxl_ctx *ctx,
libxl_cpupoolinfo * libxl_list_cpupool(libxl_ctx *ctx, int *nb_pool_out)
{
GC_INIT(ctx);
- libxl_cpupoolinfo info, *ptr, *tmp;
+ libxl_cpupoolinfo info, *ptr;
+
int i;
uint32_t poolid;
@@ -745,24 +751,29 @@ libxl_cpupoolinfo * libxl_list_cpupool(libxl_ctx *ctx,
int *nb_pool_out)
poolid = 0;
for (i = 0;; i++) {
- if (cpupool_info(gc, &info, poolid, false))
+ libxl_cpupoolinfo_init(&info);
+ if (cpupool_info(gc, &info, poolid, false)) {
+ libxl_cpupoolinfo_dispose(&info);
+ if (errno != ENOENT) goto out;
break;
- tmp = realloc(ptr, (i + 1) * sizeof(libxl_cpupoolinfo));
- if (!tmp) {
- LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "allocating cpupool info");
- libxl_cpupoolinfo_list_free(ptr, i);
- ptr = NULL;
- goto out;
}
- ptr = tmp;
+
+ ptr = libxl__realloc(NOGC, ptr, (i+1) * sizeof(libxl_cpupoolinfo));
ptr[i] = info;
poolid = info.poolid + 1;
+ /* Don't dispose of info because it will be returned to caller */
}
*nb_pool_out = i;
-out:
+
GC_FREE;
return ptr;
+
+out:
+ libxl_cpupoolinfo_list_free(ptr, i);
+ *nb_pool_out = 0;
+ GC_FREE;
+ return NULL;
}
/* this API call only list VM running on this host. A VM can
--
generated by git-patchbot for /home/xen/git/xen.git#master
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |