Commit c38e11b5 authored by Kirill Smelkov's avatar Kirill Smelkov Committed by David Gibson

bitmap: Don't crash if allocation fails in bitmap_alloc0() & friends

Currently, if allocation fails, inside bitmap_alloc0(), we'll continue
to use bitmap=NULL pointer and pass it to bitmap_zero() which will
SIGSEGV.

Cc: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Kirill Smelkov's avatarKirill Smelkov <kirr@nexedi.com>
Signed-off-by: default avatarDavid Gibson <david@gibson.dropbear.id.au>
parent d58e2fd2
......@@ -203,7 +203,8 @@ static inline bitmap *bitmap_alloc0(unsigned long nbits)
bitmap *bitmap;
bitmap = bitmap_alloc(nbits);
bitmap_zero(bitmap, nbits);
if (bitmap)
bitmap_zero(bitmap, nbits);
return bitmap;
}
......@@ -212,7 +213,8 @@ static inline bitmap *bitmap_alloc1(unsigned long nbits)
bitmap *bitmap;
bitmap = bitmap_alloc(nbits);
bitmap_fill(bitmap, nbits);
if (bitmap)
bitmap_fill(bitmap, nbits);
return bitmap;
}
......@@ -221,7 +223,7 @@ static inline bitmap *bitmap_realloc0(bitmap *bitmap,
{
bitmap = realloc(bitmap, bitmap_sizeof(nbits));
if (nbits > obits)
if ((nbits > obits) && bitmap)
bitmap_zero_range(bitmap, obits, nbits);
return bitmap;
......@@ -232,7 +234,7 @@ static inline bitmap *bitmap_realloc1(bitmap *bitmap,
{
bitmap = realloc(bitmap, bitmap_sizeof(nbits));
if (nbits > obits)
if ((nbits > obits) && bitmap)
bitmap_fill_range(bitmap, obits, nbits);
return bitmap;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment