libc/stdlib/mallocr.c (unlink)
J. Johnston
jjohnstn@redhat.com
Wed Feb 19 23:56:00 GMT 2003
I mean circular in that you do not traverse the list
until you reach a NULL pointer as one should not exist. The last element
will end up pointing forward to the first and vice-versa. If there is one element,
it should point to itself and cannot be removed via unlink.
Take a look at the first() and last() operators for bins.
/* field-extraction macros */
#define first(b) ((b)->fd)
#define last(b) ((b)->bk)
There is also a comment about the chunk list being circular:
Chunks always begin on even word boundries, so the mem portion
(which is returned to the user) is also on an even word boundary, and
thus double-word aligned.
Free chunks are stored in circular doubly-linked lists, and look like this:
As Chris has pointed out, we need to understand why you are seeing a NULL
pointer in the list. There may be a serious logic flaw occuring or something
in your program may be stepping on storage.
-- Jeff J.
Earnie Boyd wrote:
> What do you mean by ``circular''? If the pointer value is capable of
> being zero it will SIGSEGV, on some systems, if referenced.
>
> Earnie.
>
> J. Johnston wrote:
>
>> Actually, you are entirely correct. I had forgotten that "both" the
>> chunk
>> and bin lists were circular. The change will be reverted.
>>
>> Earnie, you are going to have to do some more investigating.
>>
>> -- Jeff J.
>>
>> Christopher Faylor wrote:
>>
>>> On Tue, Feb 18, 2003 at 05:35:14PM -0500, J. Johnston wrote:
>>>
>>>> Patch checked in, thanks.
>>>
>>>
>>>
>>>
>>> Isn't this a "why is the pointer NULL?" type of situation? It seems
>>> like
>>> checking for null is papering over a possible problem.
>>>
>>> cgf
>>>
>>>
>>>>> ------------------------------------------------------------------------
>>>>>
>>>>>
>>>>> 2003.02.18 Earnie Boyd <earnie@users.sf.net>
>>>>>
>>>>> * libc/stdlib/mallocr.c (unlink): Don't assign a value to a
>>>>> pointer
>>>>> with a NULL value.
>>>>>
>>>>> Index: mallocr.c
>>>>> ===================================================================
>>>>> RCS file: /cvs/src/src/newlib/libc/stdlib/mallocr.c,v
>>>>> retrieving revision 1.9
>>>>> diff -u -3 -p -r1.9 mallocr.c
>>>>> --- mallocr.c 11 Oct 2002 10:28:30 -0000 1.9
>>>>> +++ mallocr.c 18 Feb 2003 21:40:05 -0000
>>>>> @@ -1936,8 +1936,8 @@ static void do_check_malloced_chunk(p, s
>>>>> {
>>>>> \
>>>>> BK =
>>>>> P->bk; \
>>>>> FD =
>>>>> P->fd; \
>>>>> - FD->bk =
>>>>> BK; \
>>>>> - BK->fd =
>>>>> FD; \
>>>>> + if (FD) FD->bk =
>>>>> BK; \
>>>>> + if (BK) BK->fd =
>>>>> FD; \
>>>>> }
>>>>> \
>>>>>
>>>>> /* Place p as the last remainder */
>>>>
>>>>
>>>>
>>
>>
>
More information about the Newlib
mailing list