summaryrefslogtreecommitdiffstats
path: root/include/qemu
diff options
context:
space:
mode:
authorPeter Lieven <pl@kamp.de>2014-09-30 09:09:11 +0200
committerPaolo Bonzini <pbonzini@redhat.com>2014-09-30 13:30:51 +0200
commitbe4d57c1ea7f17b9cadb0150b330efd9b6026972 (patch)
treea33f866126446d10c955a1766c1965e359105bb1 /include/qemu
parent49e7e31aa00a9fb466203de19120fe5c4459cac0 (diff)
downloadhqemu-be4d57c1ea7f17b9cadb0150b330efd9b6026972.zip
hqemu-be4d57c1ea7f17b9cadb0150b330efd9b6026972.tar.gz
util: introduce bitmap_try_new
regular bitmap_new simply aborts if the memory allocation fails. bitmap_try_new returns NULL on failure and allows for proper error handling. Signed-off-by: Peter Lieven <pl@kamp.de> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'include/qemu')
-rw-r--r--include/qemu/bitmap.h13
1 files changed, 11 insertions, 2 deletions
diff --git a/include/qemu/bitmap.h b/include/qemu/bitmap.h
index 1babd5d..edf4f17 100644
--- a/include/qemu/bitmap.h
+++ b/include/qemu/bitmap.h
@@ -88,10 +88,19 @@ int slow_bitmap_andnot(unsigned long *dst, const unsigned long *bitmap1,
int slow_bitmap_intersects(const unsigned long *bitmap1,
const unsigned long *bitmap2, long bits);
-static inline unsigned long *bitmap_new(long nbits)
+static inline unsigned long *bitmap_try_new(long nbits)
{
long len = BITS_TO_LONGS(nbits) * sizeof(unsigned long);
- return g_malloc0(len);
+ return g_try_malloc0(len);
+}
+
+static inline unsigned long *bitmap_new(long nbits)
+{
+ unsigned long *ptr = bitmap_try_new(nbits);
+ if (ptr == NULL) {
+ abort();
+ }
+ return ptr;
}
static inline void bitmap_zero(unsigned long *dst, long nbits)
OpenPOWER on IntegriCloud