aboutsummaryrefslogtreecommitdiffstats
path: root/tools/libxl/libxl.h
diff options
context:
space:
mode:
authorIan Jackson <ian.jackson@eu.citrix.com>2012-04-11 14:14:13 +0100
committerIan Jackson <ian.jackson@eu.citrix.com>2012-04-11 14:14:13 +0100
commitb77efdf32a0f4b68a5229757b0ee67fbcd81b703 (patch)
treed7011caa4d0af898301d1087a32c794f1b3a2e23 /tools/libxl/libxl.h
parent9c09f9dec695c7035a4ab6a338e767d0d8a54b0c (diff)
downloadxen-b77efdf32a0f4b68a5229757b0ee67fbcd81b703.tar.gz
xen-b77efdf32a0f4b68a5229757b0ee67fbcd81b703.tar.bz2
xen-b77efdf32a0f4b68a5229757b0ee67fbcd81b703.zip
libxl: Crash (more sensibly) on malloc failure
Formally change the libxl memory allocation failure policy to "crash". Previously we had a very uneven approach; much code assumed that libxl__sprintf (for example) would never return NULL, but some code was written more carefully. We think it is unlikely that we will be able to make the library actually robust against allocation failure (since that would be an awful lot of never-tested error paths) and few calling environments will be able to cope anyway. So, instead, adopt the alternative approach: provide allocation functions which never return null, but will crash the whole process instead. Consequently, - New noreturn function libxl__alloc_failed which may be used for printing a vaguely-useful error message, rather than simply dereferencing a null pointer. - libxl__ptr_add now returns void as it crashes on failure. - libxl__zalloc, _calloc, _strdup, _strndup, crash on failure using libxl__alloc_failed. So all the code that uses these can no longer dereference null on malloc failure. While we're at it, make libxl__ptr_add use realloc rather than emulating it with calloc and free, and make it grow the array exponentially rather than linearly. Things left to do: - Remove a lot of now-spurious error handling. - Remove the ERROR_NOMEM error code. 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.h')
-rw-r--r--tools/libxl/libxl.h4
1 files changed, 4 insertions, 0 deletions
diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h
index 2aec91076d..0219f81fa8 100644
--- a/tools/libxl/libxl.h
+++ b/tools/libxl/libxl.h
@@ -194,6 +194,10 @@
* No temporary objects allocated from the pool may be explicitly freed.
* Therefore public functions which initialize a libxl__gc MUST call
* libxl__free_all() before returning.
+ *
+ * Memory allocation failures are not handled gracefully. If malloc
+ * (or realloc) fails, libxl will cause the entire process to print
+ * a message to stderr and exit with status 255.
*/
/*
* libxl types