aboutsummaryrefslogtreecommitdiffstats
path: root/tools/libxl
diff options
context:
space:
mode:
Diffstat (limited to 'tools/libxl')
-rw-r--r--tools/libxl/libxl_dm.c2
-rw-r--r--tools/libxl/libxl_utils.c28
-rw-r--r--tools/libxl/libxl_utils.h2
3 files changed, 22 insertions, 10 deletions
diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c
index 2edc734cff..936e3072bc 100644
--- a/tools/libxl/libxl_dm.c
+++ b/tools/libxl/libxl_dm.c
@@ -204,7 +204,7 @@ static char ** libxl__build_device_model_args_old(libxl__gc *gc,
}
nr_set_cpus = libxl_cpumap_count_set(&b_info->avail_vcpus);
- s = libxl_cpumap_to_hex_string(&b_info->avail_vcpus);
+ s = libxl_cpumap_to_hex_string(CTX, &b_info->avail_vcpus);
flexarray_vappend(dm_args, "-vcpu_avail",
libxl__sprintf(gc, "%s", s), NULL);
free(s);
diff --git a/tools/libxl/libxl_utils.c b/tools/libxl/libxl_utils.c
index d07a5a7a58..707306213c 100644
--- a/tools/libxl/libxl_utils.c
+++ b/tools/libxl/libxl_utils.c
@@ -491,19 +491,29 @@ int libxl_mac_to_device_nic(libxl_ctx *ctx, uint32_t domid,
int libxl_cpumap_alloc(libxl_ctx *ctx, libxl_cpumap *cpumap, int max_cpus)
{
+ GC_INIT(ctx);
int sz;
+ int rc;
- if (max_cpus < 0)
- return ERROR_INVAL;
+ if (max_cpus < 0) {
+ rc = ERROR_INVAL;
+ goto out;
+ }
if (max_cpus == 0)
max_cpus = libxl_get_max_cpus(ctx);
- if (max_cpus == 0)
- return ERROR_FAIL;
+ if (max_cpus == 0) {
+ rc = ERROR_FAIL;
+ goto out;
+ }
sz = (max_cpus + 7) / 8;
- cpumap->map = libxl__calloc(NULL, sizeof(*cpumap->map), sz);
+ cpumap->map = libxl__calloc(NOGC, sizeof(*cpumap->map), sz);
cpumap->size = sz;
- return 0;
+
+ rc = 0;
+ out:
+ GC_FREE;
+ return rc;
}
void libxl_cpumap_dispose(libxl_cpumap *map)
@@ -542,10 +552,11 @@ int libxl_cpumap_count_set(const libxl_cpumap *cpumap)
}
/* NB. caller is responsible for freeing the memory */
-char *libxl_cpumap_to_hex_string(const libxl_cpumap *cpumap)
+char *libxl_cpumap_to_hex_string(libxl_ctx *ctx, const libxl_cpumap *cpumap)
{
+ GC_INIT(ctx);
int i = cpumap->size;
- char *p = libxl__zalloc(NULL, cpumap->size * 2 + 3);
+ char *p = libxl__zalloc(NOGC, cpumap->size * 2 + 3);
char *q = p;
strncpy(p, "0x", 2);
p += 2;
@@ -554,6 +565,7 @@ char *libxl_cpumap_to_hex_string(const libxl_cpumap *cpumap)
p += 2;
}
*p = '\0';
+ GC_FREE;
return q;
}
diff --git a/tools/libxl/libxl_utils.h b/tools/libxl/libxl_utils.h
index a762734c3f..05a269a9e1 100644
--- a/tools/libxl/libxl_utils.h
+++ b/tools/libxl/libxl_utils.h
@@ -68,7 +68,7 @@ int libxl_cpumap_test(const libxl_cpumap *cpumap, int cpu);
void libxl_cpumap_set(libxl_cpumap *cpumap, int cpu);
void libxl_cpumap_reset(libxl_cpumap *cpumap, int cpu);
int libxl_cpumap_count_set(const libxl_cpumap *cpumap);
-char *libxl_cpumap_to_hex_string(const libxl_cpumap *cpumap);
+char *libxl_cpumap_to_hex_string(libxl_ctx *ctx, const libxl_cpumap *cpumap);
static inline void libxl_cpumap_set_any(libxl_cpumap *cpumap)
{
memset(cpumap->map, -1, cpumap->size);