From petm@scam.XCF.Berkeley.EDU Tue Apr 22 19:58:54 1997 Date: Tue, 22 Apr 1997 11:30:52 -0700 From: Peter Mattis To: gimp-developer@scam.XCF.Berkeley.EDU Subject: Re: [gimp-devel] [patch] gimp 0.99.8 "app" memory leaks >Found finally the source of these mysterious memory leaks! >#define GTK_CHECK_CAST(obj,cast_type,cast) \ > (gtk_object_check_cast ((GtkObject*) obj, cast_type), ((cast*) obj)) > >where OBJ is evaluated twice! Apparently, it will cause memory leaks >if used this way: Eeek! I feel like an idiot. But I also hacked up a patch. Unless I don't understand how the comma operator works, then this patch should work fine. At least, it worked fine when I tested it. It basically halved the number of calls to gtk_type_new. Dang, I feel stupid. Peter *** gtkobject.h.orig Thu Apr 17 16:37:24 1997 --- gtkobject.h Tue Apr 22 11:18:19 1997 *************** *** 52,62 **** #else /* NDEBUG */ #define GTK_CHECK_CAST(obj,cast_type,cast) \ ! (gtk_object_check_cast ((GtkObject*) obj, cast_type), ((cast*) obj)) #define GTK_CHECK_CLASS_CAST(klass,cast_type,cast) \ ! (gtk_object_check_class_cast ((GtkObjectClass*) klass, cast_type), ((cast*) klass)) #endif /* NDEBUG */ --- 52,64 ---- #else /* NDEBUG */ + extern gpointer __tmp_obj; + #define GTK_CHECK_CAST(obj,cast_type,cast) \ ! (__tmp_obj = (obj), gtk_object_check_cast (__tmp_obj, cast_type), ((cast*) __tmp_obj)) #define GTK_CHECK_CLASS_CAST(klass,cast_type,cast) \ ! (__tmp_obj = (klass), gtk_object_check_class_cast (__tmp_obj, cast_type), ((cast*) __tmp_obj)) #endif /* NDEBUG */ *** gtkobject.c.orig Tue Apr 22 11:26:53 1997 --- gtkobject.c Tue Apr 22 11:22:00 1997 *************** *** 91,96 **** --- 91,102 ---- static const char *user_data_key = "user_data"; + #ifndef NDEBUG + + gpointer __tmp_obj; + + #endif /* NDEBUG */ + /***************************************** * gtk_object_get_type: