Bad memory management?



Forgive me as I post potentially stupid questions - I've been away from
C for a while and am diving back in with a GTK app (which I'm brand new
to).  8)

In any case, here's the setup:

I create a struct that has 
GtkWidget *win, *table, *prog_bar
GdkPixmap *pixmap
GtkStyle *sty
and guint width, height

I create the window, copy the style out, set the background pixmap to
what I have in the *pixmap, copy the style back in.  All good so far.

Then I insert a table, then the progress bar.  Both of these are
referenced through appropriate variables in the struct.

So now I have a struct that has everything that I am playing with at the
moment, and I do what I do with it.

Now for the fun part.  I want to free up the memory.

The struct in question is *s.  I do the following:

gtk_widget_hide_all( s->win );

gdk_pixmap_unref( s->pixmap );
s->pixmap = NULL;
gtk_style_unref( s->sty );
s->sty = NULL;

gtk_object_destroy( GTK_OBJECT( s->prog_bar ) );
s->prog_bar = NULL;
gtk_object_destroy( GTK_OBJECT( s->table ) );
s->table = NULL;
gtk_object_destroy( GTK_OBJECT( s->win ) );
s->win = NULL;

free( s );
s = NULL;

Now, on my Mandrake box at home (with GTK 1.2.8) everything works hunky
dory.  However, on my RH 6.2 box at work (with GTK 1.2.9), it
segfaults.  

I'm imagining it has something to do with not knowing what the heck I'm
doing with destroying the gtk objects, but I was hoping perhaps you
folks could point out what exactly I was doing wrong here?

--
Pretend there's a witty saying here.

Cole Tuininga




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]