dbus_realloc: don't crash if realloc() returns NULL while using guards
authorSimon McVittie <simon.mcvittie@collabora.co.uk>
Thu, 23 Jun 2011 10:26:38 +0000 (11:26 +0100)
committerSimon McVittie <simon.mcvittie@collabora.co.uk>
Tue, 21 Feb 2012 15:07:56 +0000 (15:07 +0000)
Reviewed-by: Guillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=41048

dbus/dbus-memory.c

index c5f4641..08698d4 100644 (file)
@@ -588,8 +588,11 @@ dbus_realloc (void  *memory,
           block = realloc (((unsigned char*)memory) - GUARD_START_OFFSET,
                            bytes + GUARD_EXTRA_SIZE);
 
-         old_bytes = *(dbus_uint32_t*)block;
-          if (block && bytes >= old_bytes)
+          if (block == NULL)
+            return NULL;
+
+          old_bytes = *(dbus_uint32_t*)block;
+          if (bytes >= old_bytes)
             /* old guards shouldn't have moved */
             check_guards (((unsigned char*)block) + GUARD_START_OFFSET, FALSE);