diff options
author | Ian Jackson <ian.jackson@eu.citrix.com> | 2012-04-11 14:14:14 +0100 |
---|---|---|
committer | Ian Jackson <ian.jackson@eu.citrix.com> | 2012-04-11 14:14:14 +0100 |
commit | 96d60b3e3e9bdd1c50389819293945622e3a81d8 (patch) | |
tree | 7fc7d93aaee650fc7110a4f437423b7a331cb89b /tools/libxl/libxl_internal.c | |
parent | b77efdf32a0f4b68a5229757b0ee67fbcd81b703 (diff) | |
download | xen-96d60b3e3e9bdd1c50389819293945622e3a81d8.tar.gz xen-96d60b3e3e9bdd1c50389819293945622e3a81d8.tar.bz2 xen-96d60b3e3e9bdd1c50389819293945622e3a81d8.zip |
libxl: Make libxl__zalloc et al tolerate a NULL gc
Arrange that if we pass NULL as a gc, we simply don't register the
pointer. This instantly gives us non-gc'ing but error-checking
versions of malloc, realloc, vasprintf, etc.
Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
Committed-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
Diffstat (limited to 'tools/libxl/libxl_internal.c')
-rw-r--r-- | tools/libxl/libxl_internal.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/tools/libxl/libxl_internal.c b/tools/libxl/libxl_internal.c index 4ed941233c..b89aef71ce 100644 --- a/tools/libxl/libxl_internal.c +++ b/tools/libxl/libxl_internal.c @@ -34,6 +34,9 @@ void libxl__ptr_add(libxl__gc *gc, void *ptr) { int i; + if (!gc) + return; + if (!ptr) return; @@ -101,7 +104,7 @@ void *libxl__realloc(libxl__gc *gc, void *ptr, size_t new_size) if (ptr == NULL) { libxl__ptr_add(gc, new_ptr); - } else if (new_ptr != ptr) { + } else if (new_ptr != ptr && gc != NULL) { for (i = 0; i < gc->alloc_maxsize; i++) { if (gc->alloc_ptrs[i] == ptr) { gc->alloc_ptrs[i] = new_ptr; |