[EMAIL PROTECTED] (Tijs van Bakel) writes:

> In lib/libgii/gii/gii.c, in the function
> 
>         int giiClose(struct gii_input *inp);
> 
> there is this code at the end of the closing loop:
> 
>               curr = curr->next;
>                 _giiInputFree(curr->prev);
>         } while (curr!=inp);  /* looped through once. */
> 
> The call to _giiInputFree() segfaults if curr==inp, so I changed it
> into this:

Ah, thanks for finding that one! This should fix it properly:

diff -u -r1.22 gii.c
--- gii/gii.c   1999/09/05 22:18:35     1.22
+++ gii/gii.c   2000/04/18 23:07:09
@@ -692,6 +692,8 @@
        _giiEvQueueDestroy(inp);        /* This destroys _all_ queues ! */
 
        do {
+               struct gii_input *prev;
+
                curr->queue = NULL;     /* For better error catching. */
 
                if (curr->GIIclose) {
@@ -702,9 +704,10 @@
                        _giiCloseDL(curr->dlhand);
                        free(curr->dlhand);
                }
+               prev = curr;
                curr = curr->next;
-               _giiInputFree(curr->prev);
-       } while (curr!=inp);    /* looped through once. */
+               _giiInputFree(prev);
+       } while (curr != inp);  /* looped through once. */
 
        return rc;
 }


> Unfortunately this didn't solve the segfault I get when the simple
> test program exits.  Again, here is a simple program that exits with a
> segfault when run from the svgalib target:
> 
> #include <ggi/ggi.h>
> int main()
> {
>   ggi_visual_t v;
>   ggiInit();
> 
>   v = ggiOpen(NULL);
>   ggiSetGraphMode(v,320,200,GGI_AUTO,GGI_AUTO,GT_8BIT);
>   ggiClose(v);
> 
>   v = ggiOpen(NULL);
>   ggiSetGraphMode(v,320,200,GGI_AUTO,GGI_AUTO,GT_8BIT);
>   ggiClose(v);
> 
>   return 0;
> }
> 
> 
> Any ideas/hints/help ?

This is not related to the GII bug above.
It is due to svgalib registering an atexit() handler. As atexit
handlers can't be unregistered and svgalib is not in memory when
the program terminates we get a segfault. For normal use we work
around this, but if you open the svgalib target several times it
won't work and you'll get a segfault. I'll have a look at making
the workaround a bit better when my local copy of LibGGI compiles
again.

//Marcus
-- 
-------------------------------+------------------------------------
        Marcus Sundberg        | http://www.stacken.kth.se/~mackan
 Royal Institute of Technology |       Phone: +46 707 295404
       Stockholm, Sweden       |   E-Mail: [EMAIL PROTECTED]

Reply via email to