nanogui: XCreateWindow/XDestroyWindow memory leak?


Previous by date: 15 Nov 2007 20:10:35 +0000 Re: save image, Greg Haerr
Next by date: 15 Nov 2007 20:10:35 +0000 Re: XCreateWindow/XDestroyWindow memory leak?, Martin Kajdas
Previous in thread: 15 Nov 2007 20:10:35 +0000 Re: XCreateWindow/XDestroyWindow memory leak?, Greg Haerr
Next in thread: 15 Nov 2007 20:10:35 +0000 Re: XCreateWindow/XDestroyWindow memory leak?, Martin Kajdas

Subject: RE: [nanogui] XCreateWindow/XDestroyWindow memory leak?
From: "Martin Kajdas" ####@####.####
Date: 15 Nov 2007 20:10:35 +0000
Message-Id: <CF2BB830A62F914F848E5AD5FFF57AC24F993F@mkmail.MKPROD.COM>

The problem is with _nxAddProperty function in the way is creates linked
lists of windows and properties.
The first window/property is not tested correctly and it is duplicated,
and when deletion is performed,
the duplication is removed but not the original and leak occurs.

Also, using XGetAtomName inside printf causes another leak because the
return string is allocated (strdup) on heap and never released.
There is nothing wrong in Atom.c

The patch for ChProperty.c is:
 
--- ChProperty.c.org	2002-09-21 22:52:29.000000000 +0000
+++ ChProperty.c	2007-11-15 12:49:27.000000000 +0000
@@ -30,12 +30,13 @@
 			(struct windows *) Xcalloc(sizeof(struct
windows), 1);
 	} else {
 		struct windows *t = window_list[hash];
-		while (t->next) {
+		for (;;) {
 			if (t->w == w) {
 				win = t;
 				break;
 			}
-
+			if (t->next == NULL)
+				break;
 			t = t->next;
 		}
 
@@ -44,17 +45,19 @@
 				(struct windows *) Xcalloc(sizeof(struct
windows), 1);
 	}
 
+	win->w = w;
 	if (!win->properties)
 		prop = win->properties =
 			(struct window_props *) Xcalloc(sizeof(struct
window_props), 1);
 	else {
 		struct window_props *t = win->properties;
-		while (t->next) {
+		for (;;) {
 			if (t->property == property) {
 				prop = t;
 				break;
 			}
-
+			if (t->next == NULL)
+				break;
 			t = t->next;
 		}
 
@@ -176,7 +179,6 @@
 		Atom type, int format, int mode,
 		_Xconst unsigned char *data, int nelements)
 {
-printf("XChangeProperty %s\n", XGetAtomName(display, property));
 	return _nxAddProperty(w, property, type, format, mode,
 			       data, nelements);
 }

Previous by date: 15 Nov 2007 20:10:35 +0000 Re: save image, Greg Haerr
Next by date: 15 Nov 2007 20:10:35 +0000 Re: XCreateWindow/XDestroyWindow memory leak?, Martin Kajdas
Previous in thread: 15 Nov 2007 20:10:35 +0000 Re: XCreateWindow/XDestroyWindow memory leak?, Greg Haerr
Next in thread: 15 Nov 2007 20:10:35 +0000 Re: XCreateWindow/XDestroyWindow memory leak?, Martin Kajdas


Powered by ezmlm-browse 0.20.