MallocScribble - how is it supposed to work?
MallocScribble - how is it supposed to work?
- Subject: MallocScribble - how is it supposed to work?
- From: Mark Dalrymple <email@hidden>
- Date: Mon, 13 Jun 2005 16:21:52 -0400
Greetings,
I'm playing around setting the MallocScribble environment variable to
try to get it do what the man pages says it will do (write 0x55's to
the block of memory upon a free()).
What I'm seeing is that for smaller allocations (say less than 15K),
nothing gets written to the freed memory. I can happily access it.
If it's an allocation larger than about 15K, I SegV trying to access
the freed memory. (granted, choking when accessing the memory isn't
necessarily a bad thing), but I'm curious if I'm either using it
wrong, or if it doesn't actually scribble memory on smaller blocks.
This is in Tiger / Xcode 2.1, but someone has tried this on a Panther
10.3.9 system and it behaves the same.
Here's a simple app:
// scribble.m -- exercise MallocScribble
/* compile wth:
gcc -g -Wall -o scribble scribble.m
*/
#import <stdlib.h> // for malloc()
#import <stdio.h> // for printf()
#import <string.h> // for strcpy()
int main (int argc, char *argv[])
{
char *string = strdup ("hello I seem to be a fish thank you very
much");
printf ("before: %s\n", string);
free (string);
printf ("after: %s\n", string); // expecting "UUUUUUU"
return (0);
} // main
And a sample run:
% gcc -g -Wall -o scribble scribble.m
% setenv MallocScribble 1
% ./scribble
(14715) malloc: enabling scribbling to detect mods to free blocks
before: hello I seem to be a fish thank you very much
after: hello I seem to be a fish thank you very much
So the env var is being picked up by the malloc libs. The same code
in Jaguar would print out a line of UUUUUs.
Thanks in advance,
++Mark Dalrymple, email@hidden
http://borkware.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden