Mail Archives: djgpp/2004/10/08/04:13:07
Martin Str|mberg wrote:
>JC <jessechao AT comcast DOT net> wrote:
>
>
>>I used djgpp to develop a simple program, using dosmemget(),
>>to dump some DOS memory. The code is like following:
>>
>>
>
>
>
>> p = (UINT8 *)malloc(len+1);
>> if (p == NULL)
>> {
>> ...
>> }
>> dosmemget(addr, len, p);
>> /* Code to printf the contents in *p */
>> ...
>> free(p);
>>
>>
>
>
>
>>The code compiled & ran fine. But when the code execute
>>the free(). The code crashed and got SIGSEG error:
>>
>>
>
>
>
>> Exiting due to signal SIGSEGV
>> General Protection Fault at eip=00006ac4
>>
>>
>
>
>
>>Anyone can help me on this?
>>
>>
>
>1. Remove that UINT8 * cast.
>
>2. If that doesn't help you need to give more information, because
>malloc() and free() work fine so it must be something else.
>
>
>Right,
>
> MartinS
>
>
>
Removing the cast doesn't make any difference for free(). The cast
simply says that p should be considered as a pointer to UINT8 instead of
o void. Free may crash if there is a memory overwrite somewhere after
the comment
Code to printf the contents in *p
When the memory gets corrupted free() may fail.
Andras
- Raw text -