[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
linking with libmcheck ruins output of malloc_usable_size()
From: |
Peter Jay Salzman |
Subject: |
linking with libmcheck ruins output of malloc_usable_size() |
Date: |
Tue, 6 May 2003 10:24:13 -0700 |
User-agent: |
Mutt/1.5.3i |
Proof of concept code:
#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <mcheck.h>
// On my system, size_t is an unsigned int.
int main(void)
{
char *p = (char *) malloc(sizeof(char));
if (p == NULL)
abort();
printf("I requested %u bytes.\n", sizeof(char));
printf("p was allocated %u bytes.\n", malloc_usable_size(p));
return 0;
}
Output on glibc 2.1:
$ gcc -W -Wall try.c
$ ./a.out
I requested 1 bytes.
p was allocated 12 bytes.
$ gcc -W -Wall try.c -lmcheck
$ ./a.out
I requested 1 bytes.
p was allocated 0 bytes.
Output on glibc 2.3:
$ gcc -W -Wall try.c
$ ./a.out
I requested 1 bytes.
p was allocated 12 bytes.
$ gcc -W -Wall try.c -lmcheck
$ ./a.out
I requested 1 bytes.
p was allocated 4141754496 bytes.
Either way, the output of malloc_usable_size() is wrong when the program
is linked with libmcheck. I WISH I had 4141754496 bytes of memory! :-)
Please cc me, since I'm not on the glibc-bug list.
Thanks guys!
Pete
--
GPG Instructions: http://www.dirac.org/linux/gpg
GPG Fingerprint: B9F1 6CF3 47C4 7CD8 D33E 70A9 A3B9 1945 67EA 951D
pgpSBw6pix0cl.pgp
Description: PGP signature
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- linking with libmcheck ruins output of malloc_usable_size(),
Peter Jay Salzman <=