> > Solves it ?
> No. See:
>
> > int ggiWhateverDetach(ggi_visual_t vis)
> > {
> > int rc;
> > whateverext *we = LIBGGI_WHATEVEREXT(vis);
> > void *mypriv = we->mypriv; /* pointer still valid. Cache it. */
> >
> > rc = ggiExtensionDetach(vis,ggiWhateverID);
> > GGIDPRINT("Detached Whatever extension from %p. rc=%i\n", vis, rc);
> > if (rc==0) {
> free(mypriv);
> free(we);
NOOO ! That's not my code. I didn't free we in mine. Why ? Well:
You don't free we. You don't allocate it (the first Attach does it for you)
so you don't deallocate it !
> I am searching for a way to do 'free(we)' without segfaulting.
> Your way crashs.
You may not free we. The Extension mechanism does that by itself and it is
good that it does so. If you want to have some linked list or whatever
there do it like this:
typedef struct {
mylist_t *rootptr;
} whateverext;
When ggiWhateverAttach() runs, you check if ggiExtensionAttach returns 0.
if so, you do:
if (0==rc_fromextattach) {
whateverext *we = LIBGGI_WHATEVEREXT(vis);
we->rootptr=malloc(sizeof(mylist_t));
we->rootptr.data=bla;
we->rootptr.next=NULL;
...
}
When Detaching, you just cache we->rootptr as I showed above and then
call Detach(). If it happens to return 0, it has just destroyed the
former memory area that contained we->rootptr (i.e. *we).
But fortunately we have a copy and can now destroy its contents by whatever
algorithm you wish.
> /* Free the galloc visual-extension structure itself.
> */
> if (LIBGGI_GALLOCEXT(vis) != NULL) {
> free (LIBGGI_GALLOCEXT(vis));
> } /* if */
You don't do that. See above. You didn't alloc it, you don't free it.
> > No, it frees the extension struct - nothing more.
> And that's too much.
It (i.e. the extension handling system) has allocated it ! So it should free
it.
CU, ANdy
--
Andreas Beck | Email : <[EMAIL PROTECTED]>