Re: A debugging implementation of malloc
- From: Keith Thompson <kst-u@xxxxxxx>
- Date: Mon, 26 Jun 2006 01:38:39 GMT
Eric Sosman <esosman@xxxxxxxxxxxxxxxxxxx> writes:
jacob navia wrote:[...]
In the C tutorial for lcc-win32, I have a small chapter
about a debugging implementation of malloc.
[...]
Others have commented on the alignment issues, and on
the wisdom of initializing newly-allocated memory to a
"useful" value like all zeroes. I've got a few further
suggestions:
When an allocation is released, consider filling it
with garbage. This may help catch erroneous uses of an
area after it's been freed, as in the famously incorrect
code for freeing a linked list:
for (ptr = head; ptr != NULL; ptr = ptr->next)
free(ptr);
Better yet: when allocating memory, fill it with one kind of garbage
(to detect, though not reliably, the error of accessing uninitialized
memory), and when releasing it, fill it with another kind of garbage
(to detect, though not reliably, the distinct error of attempting to
access freed memory). It could be a substantial performance hit, but
it might be worth it if it detects errors.
--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
.
- Follow-Ups:
- Re: A debugging implementation of malloc
- From: Eric Sosman
- Re: A debugging implementation of malloc
- References:
- A debugging implementation of malloc
- From: jacob navia
- Re: A debugging implementation of malloc
- From: Eric Sosman
- A debugging implementation of malloc
- Prev by Date: Re: How to connect SQL database in C programs
- Next by Date: Re: economizing with functions that do the same thing
- Previous by thread: Re: A debugging implementation of malloc
- Next by thread: Re: A debugging implementation of malloc
- Index(es):
Relevant Pages
|
|