]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
helgrind: If hg_cli__realloc fails, return NULL.
authorMark Wielaard <mark@klomp.org>
Mon, 8 Jun 2020 11:24:47 +0000 (13:24 +0200)
committerMark Wielaard <mark@klomp.org>
Mon, 8 Jun 2020 11:24:54 +0000 (13:24 +0200)
helgrind would not handle a failing realloc correctly and assume
cli_malloc would always succeed. If cli_malloc fails in hg_cli__realloc
do like dh and massif and fail the realloc call by returning NULL.

helgrind/hg_main.c

index 8b8dd054987d2227a71ea7f86efdb19ae4c5015b..26b0c5a1233be2a950b16896cf001b4dfd728cce 100644 (file)
@@ -4331,6 +4331,11 @@ static void* hg_cli__realloc ( ThreadId tid, void* payloadV, SizeT new_size )
    /* else */ {
       /* new size is bigger */
       Addr p_new = (Addr)VG_(cli_malloc)(VG_(clo_alignment), new_size);
+      if (!p_new) {
+         // Nb: if realloc fails, NULL is returned but the old block is not
+         // touched.  What an awful function.
+         return NULL;
+      }
 
       /* First half kept and copied, second half new */
       // FIXME: shouldn't we use a copier which implements the