]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Fix NULL return value handling
authorDJ Delorie <dj@delorie.com>
Fri, 15 Jul 2016 22:26:14 +0000 (18:26 -0400)
committerDJ Delorie <dj@delorie.com>
Fri, 15 Jul 2016 22:26:14 +0000 (18:26 -0400)
Decided that a call that returns NULL should be encoded in the
workload but that the simulator should just skip those calls,
rather than skip them in the converter.

malloc/trace2wl.cc
malloc/trace_run.c

index aa53fb36768c458d4d06d3003cef839c57ca59cc..5fe7b556ec6864e0e4d70bcb80d278ff480d2fdf 100644 (file)
@@ -276,14 +276,17 @@ main(int argc, char **argv)
        case __MTB_TYPE_MALLOC:
        case __MTB_TYPE_CALLOC:
          acq_ptr (thread, pa2);
-         if (pa2->valid)
+         if (pa2 && pa2->valid)
            printf ("%d: pointer %p malloc'd again?  %d:%s\n", i, pa2->ptr, pa2->reason_idx, pa2->reason);
          thread->add (r->type == __MTB_TYPE_MALLOC ? C_MALLOC : C_CALLOC);
-         thread->add_int (pa2->idx);
+         thread->add_int (pa2 ? pa2->idx : 0);
          thread->add_int (r->size);
-         pa2->valid = 1;
-         pa2->reason = "malloc";
-         pa2->reason_idx = i;
+         if (pa2)
+           {
+             pa2->valid = 1;
+             pa2->reason = "malloc";
+             pa2->reason_idx = i;
+           }
          break;
 
        case __MTB_TYPE_FREE:
index a42e81d80facce7fbf2f816b74ed059dad8c25de..e64b18981a39eb3857a10e335fdfbdd32abfebce 100644 (file)
@@ -242,6 +242,9 @@ thread_common (void *my_data_v)
          p2 = get_int (&cp);
          sz = get_int (&cp);
          dprintf("op %d:%ld %ld = MALLOC %ld\n", (int)me, cp-data, p2, sz);
+         /* we can't force malloc to return NULL (fail), so just skip it.  */
+         if (p2 == 0)
+           break;
          if (p2 > n_ptrs)
            myabort();
          stime = rdtsc_s();
@@ -271,6 +274,9 @@ thread_common (void *my_data_v)
          p2 = get_int (&cp);
          sz = get_int (&cp);
          dprintf("op %d:%ld %ld = CALLOC %ld\n", (int)me, cp-data, p2, sz);
+         /* we can't force calloc to return NULL (fail), so just skip it.  */
+         if (p2 == 0)
+           break;
          if (p2 > n_ptrs)
            myabort();
          if (ptrs[p2])
@@ -303,6 +309,16 @@ thread_common (void *my_data_v)
          if (ptrs[p1])
            atomic_rss (-sizes[p1]);
          free_wipe(p1);
+         /* we can't force realloc to return NULL (fail), so just skip it.  */
+         if (p2 == 0)
+           {
+             if (p1)
+               {
+                 free ((void *)ptrs[p1]);
+                 ptrs[p1] = 0;
+               }
+             break;
+           }
          stime = rdtsc_s();
          Q1;
 #ifdef MDEBUG