Fix a buglet in malloc/mtrace.pl
Commit Message
Greetings,
For BZ #18757, I made a test which forces fmemopen() to fail due to
out-of-memory:
+ errno = 0;
+ stream = fmemopen (NULL, ~0, "w");
+ if (stream)
+ {
+ printf ("fmemopen: expected NULL, got %p\n", stream);
+ fclose (stream);
+ return 3;
+ }
+ if (errno != ENOMEM)
+ {
+ printf ("fmemopen: got %i, expected ENOMEM (%i)\n", errno, ENOMEM);
+ return 20;
+ }
+
return 0;
}
But that caused libio/test-fmemopen-mem to fail like so:
Memory not freed:
-----------------
Address Size Caller
000000000000000000 0xffffffffffffffff at 0x7f023582e3c8
This is of course completely bogus.
The comment in malloc/mtrace.c:
165 /* We could be printing a NULL here; that's OK. */
166 fprintf (mallstream, "+ %p %#lx\n", hdr, (unsigned long int) size);
--
242 /* We could be printing a NULL here; that's OK. */
243 fprintf (mallstream, "+ %p %#lx\n", hdr, (unsigned long int) size);
suggests that perhaps mtrace.pl was intended to filter such entries out.
Attached patch does that.
Thanks,
2015-08-13 Paul Pluzhnikov <ppluzhnikov@google.com>
* malloc/mtrace.pl: Filter out NULL entries.
Comments
Paul Pluzhnikov <ppluzhnikov@gmail.com> writes:
> diff --git a/malloc/mtrace.pl b/malloc/mtrace.pl
> index 0737890..4f80429 100644
> --- a/malloc/mtrace.pl
> +++ b/malloc/mtrace.pl
> @@ -167,7 +167,7 @@ while (<DATA>) {
> printf ("+ %#0@XXX@x Alloc %d duplicate: %s %s\n",
> hex($allocaddr), $nr, &location($addrwas{$allocaddr}),
> $where);
> - } else {
> + } elsif ($allocaddr != "(nil}") {
Can this ever be false?
Andreas.
@@ -167,7 +167,7 @@ while (<DATA>) {
printf ("+ %#0@XXX@x Alloc %d duplicate: %s %s\n",
hex($allocaddr), $nr, &location($addrwas{$allocaddr}),
$where);
- } else {
+ } elsif ($allocaddr != "(nil}") {
$allocated{$allocaddr}=$howmuch;
$addrwas{$allocaddr}=$where;
}