Fix realloc wrappers to handle the out of memory case properly - if
the call to VG_(cli_malloc) returns NULL then don't try and copy the
data or register a new block and just leave the old block in place
instead, but still return NULL to the caller.

Fixes bug 109487 and it's duplicates.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@4875 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/massif/ms_main.c b/massif/ms_main.c
index cc4c138..c373c86 100644
--- a/massif/ms_main.c
+++ b/massif/ms_main.c
@@ -802,22 +802,26 @@
    } else {
       // new size is bigger;  make new block, copy shared contents, free old
       p_new = VG_(cli_malloc)(VG_(clo_alignment), new_size);
-      VG_(memcpy)(p_new, p_old, old_size);
-      VG_(cli_free)(p_old);
+      if (p_new) {
+         VG_(memcpy)(p_new, p_old, old_size);
+         VG_(cli_free)(p_old);
+      }
    }
-   
-   old_where = hc->where;
-   new_where = get_XCon( tid, /*custom_malloc*/False);
 
-   // Update HP_Chunk
-   hc->data  = (Addr)p_new;
-   hc->size  = new_size;
-   hc->where = new_where;
+   if (p_new) {
+      old_where = hc->where;
+      new_where = get_XCon( tid, /*custom_malloc*/False);
 
-   // Update XPt curr_space fields
-   if (clo_heap) {
-      if (0 != old_size) update_XCon(old_where, -old_size);
-      if (0 != new_size) update_XCon(new_where,  new_size);
+      // Update HP_Chunk
+      hc->data  = (Addr)p_new;
+      hc->size  = new_size;
+      hc->where = new_where;
+
+      // Update XPt curr_space fields
+      if (clo_heap) {
+         if (0 != old_size) update_XCon(old_where, -old_size);
+         if (0 != new_size) update_XCon(new_where,  new_size);
+      }
    }
 
    // Now insert the new hc (with a possibly new 'data' field) into