https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88063

--- Comment #13 from Tom de Vries <vries at gcc dot gnu.org> ---
Comment on attachment 45063
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=45063
combined patch

>+  // We only kept the list of units to free them on failure.  On
>+  // success the units are retained, pointed to by the entries in
>+  // addrs.
>+  units.alc += units.size;
>+  units.size = 0;
>+  backtrace_vector_release (state, &units, error_callback, data);

If I force mmap.c to alloc.c like so:
...
diff --git a/libbacktrace/mmap.c b/libbacktrace/mmap.c
index 32fcba62399..e7fea31b095 100644
--- a/libbacktrace/mmap.c
+++ b/libbacktrace/mmap.c
@@ -1,3 +1,5 @@
+#include "alloc.c"
+#if 0
 /* mmap.c -- Memory allocation with mmap.
    Copyright (C) 2012-2018 Free Software Foundation, Inc.
    Written by Ian Lance Taylor, Google.
@@ -323,3 +325,4 @@ backtrace_vector_release (struct backtrace_state *state,
   vec->alc = 0;
   return 1;
 }
+#endif
...

we get:
...
$ ./btest
realloc: No such file or directory
realloc: No such file or directory
realloc: No such file or directory
FAIL: backtrace_full noinline
...

because realloc happens to return NULL when called with size == 0 in
backtrace_vector_release, and then backtrace_vector_release calls the error
callback:
...
  vec->base = realloc (vec->base, vec->size);
  if (vec->base == NULL)
    {
      error_callback (data, "realloc", errno);
      return 0;
    }
...

Fixed by patch submitted here:
https://gcc.gnu.org/ml/gcc-patches/2018-11/msg01914.html

Reply via email to