[En-Nut-Discussion] Should free test DEADBEEF by default?
Alain M.
alainm at pobox.com
Tue Apr 22 18:40:50 CEST 2008
>> Is there a good reason to/not check the DEADBEEF when freeing mem. After
>> all it's likely that (1) the boundaries were not obeyed or (2) a wrong
>> pointer got freed. Shouldn't free just return -1 in this case?
>
> Without a mmu you does not have much possibilities to detect buffer
> overflows.
There are many libs that check valid stack operations and don't relly on
mmu. I cannot leave without them... What they usually do is:
1) errors are reported to some error log output
2) something like DEADBEEF is tested both at the begining and the end of
the allocated memory to detect both overrun and underrun
3) a list of all allocated blocks is kept somewhere, it has the line
that allocated that block (a macro is used for that). This is used to
report information about errors
4) invalid deletes (pointers that are not in the list), double delletes
and left-overs (memory leaks) reported and protected
5) out of memory are reported on log output
6) periodic tests are performed to check stack level
7) allocated memory can be pefilled with a pattern, it helps to
reproduce errors.
I have used it for a long time, I have fiddled with the macros a lot and
debugged one version MSS
<http://hem.passagen.se/blizzar/mss/mssdoc.html> that is GPL and a dos
one that has no sources (comercial)
If you are going to develop something similar, I am willing to help :)
Of course, this is only marginaly usefull with little memory, but on
something like an ARM9 with SDRAM it can be most usefull
Alain
More information about the En-Nut-Discussion
mailing list