> > *) Linked lists in libng are built by linking to a root pointer, that is
> > allocated by the caller. This means that if you have a linked list as
> > member of a struct, the first item in the list will actually be that
> > member. Furthermore, it's a doubly linked, circular list. This is all
> > fine, as long as you use the original root pointer. As soon as you copy
> > it, for example by assigning the struct, the root pointer will be at a
> > different address. However, inside the linked list there are two
pointers
> > pointing to the old address, so as soon as a function traverses the
entire
> > list, you will have a dangling pointer bug.
> This is how things may go, but I think the dangling pointer problem has a
> different cause in this case. I think so because of the unlikely value of
the
> pointer in an otherwise correctly filled structure for the 'Gain Level'
> attribute. I think there is just some buggy code in libng that happens to
> overwrite the pointer with something else.

No, after examining the code I think I agree with Willem Monsuwe. The
problem is the linked list head is the first element and is embedded in the
ng_devstate, then when you copy the struct the pointer to it from the second
and last elements is invalidated.
There are 2 ways around this (if indeed that is correct), 1 is a very quick
hack that 'should' work: After the line:
  captureItem->dev = dev;
Add these lines:
  captureItem->dev->attrs->next->prev = &(captureItem->dev.attrs);
  captureItem->dev->attrs->prev->next = &(captureItem->dev.attrs);

The other, more correct, way is to not use the temporary struct "struct
ng_devstate dev;" and create the captureItem earlier so that whenever we
used the variable dev you use the structure actually in captureItem.


Harry, a quick way to tell if that actually is the problem is in your
stacktrace where you gave the output for id 1 (where I'm assuming that id 1
was the first call) try giving the value of &(&capItem->dev)->attrs and see
if it actually is the value of the prev from the first and next from the
last (as they are equal!).


Anyway try the hack above and cross your fingers (I think that is supposed
to be .attrs and not ->attrs).

Lio








-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Amsn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/amsn-devel

Reply via email to