Re: memprof reports memory leak with GtkCalendar



On Thu, Nov 16, 2000 at 07:21:05PM -0800, Evan Martin wrote:
> memprof finds a memory leak when I use the GtkCalendar widget.
> 
> The attached test program demonstrates this:
> It creates a window with a button, which, when clicked, pops up another
> window containing a calendar.
> As I understand GTK, closing this window should properly destroy the calendar.
> 
> I have also attached the memprof leak information after running the test
> program with debug versions of the GTK libraries, and popping up a calendar
> twice.
> 
> Is this a true leak?  Or is memprof misreporting?

I am sure that this is really memleak.
Try the attached patch.
--- gtk/gtkcalendar.c.orig	Fri Nov 17 13:29:25 2000
+++ gtk/gtkcalendar.c	Fri Nov 17 16:04:54 2000
@@ -258,6 +258,7 @@
 
 static void gtk_calendar_class_init	(GtkCalendarClass *class);
 static void gtk_calendar_init		(GtkCalendar *calendar);
+static void gtk_calendar_destroy	(GtkObject *calendar);
 static void gtk_calendar_realize	(GtkWidget *widget);
 static void gtk_calendar_unrealize	(GtkWidget *widget);
 static void gtk_calendar_draw_focus	(GtkWidget *widget);
@@ -364,6 +365,7 @@
   widget_class->focus_out_event = gtk_calendar_focus_out;
   widget_class->style_set = gtk_calendar_style_set;
   widget_class->state_changed = gtk_calendar_state_changed;
+  object_class->destroy = gtk_calendar_destroy;
   
   gtk_calendar_signals[MONTH_CHANGED_SIGNAL] =
     gtk_signal_new ("month_changed",
@@ -1138,6 +1140,14 @@
       gdk_window_destroy (private_data->main_win);
       private_data->main_win = NULL;      
     }
+  if (private_data->day_name_win)
+    {
+      gdk_window_set_user_data (private_data->day_name_win, NULL);
+      gdk_window_destroy (private_data->day_name_win);
+      private_data->day_name_win = NULL;      
+    }
+  if (calendar->xor_gc) gdk_gc_unref (calendar->xor_gc);
+  if (calendar->gc) gdk_gc_unref (calendar->gc);
   
   if (GTK_WIDGET_CLASS (parent_class)->unrealize)
     (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget);
@@ -2641,6 +2651,16 @@
   gtk_calendar_paint_day (widget, calendar->focus_row, calendar->focus_col);
   
   return FALSE;
+}
+
+static void
+gtk_calendar_destroy (GtkObject *object)
+{
+  GtkCalendarPrivateData *private_data;
+  private_data = GTK_CALENDAR_PRIVATE_DATA (object);
+  g_free (private_data);
+  if (GTK_OBJECT_CLASS (parent_class)->destroy)
+    (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
 }
 
 static gint


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