Репозиторий Sisyphus
Последнее обновление: 1 октября 2023 | Пакетов: 18631 | Посещений: 37737441
en ru br
Репозитории ALT
S:1.17.0-alt9
5.1: 1.17.0-alt8
4.1: 1.17.0-alt6
4.0: 1.17.0-alt6
3.0: 1.17.0-alt6
www.altlinux.org/Changes

Группа :: Графика
Пакет: xli

 Главная   Изменения   Спек   Патчи   Sources   Загрузить   Gear   Bugs and FR  Repocop 

Патч: 150-fix-x-resource-leak.patch
Скачать


diff --git a/xli/root.c b/xli/root.c
index 17ed9bd..d187a2f 100644
--- a/xli/root.c
+++ b/xli/root.c
@@ -15,17 +15,6 @@
 
 #define RETAIN_PROP_NAME	"_XSETROOT_ID"
 
-static void updateProperty(Display * dpy, Window w, char *name, Atom type, int format, int data, int nelem)
-{
-	/* intern the property name */
-	Atom atom = XInternAtom(dpy, name, 0);
-
-	/* create or replace the property */
-	XChangeProperty(dpy, w, atom, type, format, PropModeReplace,
-			(unsigned char *) &data, nelem);
-}
-
-
 /* Sets the close-down mode of the client to 'RetainPermanent'
  * so all client resources will be preserved after the client
  * exits.  Puts a property on the default root window containing
@@ -36,9 +25,15 @@ static void preserveResource(Display * dpy, Window w)
 {
 	/* create dummy resource */
 	Pixmap pm = XCreatePixmap(dpy, w, 1, 1, 1);
+        unsigned char *data = (unsigned char *) ±
 
-	/* create/replace the property */
-	updateProperty(dpy, w, RETAIN_PROP_NAME, XA_PIXMAP, 32, (int) pm, 1);
+        /* intern the property name */
+        char *name = RETAIN_PROP_NAME;
+        Atom atom = XInternAtom(dpy, name, 0);
+
+        /* create or replace the property */
+        XChangeProperty(dpy, w, atom, XA_PIXMAP, 32, PropModeReplace,
+                        data, sizeof(Pixmap)/4);
 
 	/* retain all client resources until explicitly killed */
 	XSetCloseDownMode(dpy, RetainPermanent);
@@ -52,30 +47,57 @@ static void preserveResource(Display * dpy, Window w)
 static void freePrevious(Display * dpy, Window w)
 {
 	Pixmap *pm;
-	Atom actual_type;	/* NOTUSED */
+        unsigned char *charpm;
+        Atom actual_type;
 	int format;
-	int nitems;
-	int bytes_after;
+        unsigned long nitems;
+        unsigned long bytes_after;
+        int returncode;
 
 	/* intern the property name */
 	Atom atom = XInternAtom(dpy, RETAIN_PROP_NAME, 0);
 
-	/* look for existing resource allocation */
-	if ((XGetWindowProperty(dpy, w, atom, 0, 1, 1 /*delete */ ,
-				AnyPropertyType, &actual_type, &format,
-				(unsigned long *) &nitems,
-				(unsigned long *) &bytes_after,
-				(unsigned char **) &pm) == Success) &&
-	    nitems == 1)
-		if ((actual_type == XA_PIXMAP) && (format == 32) &&
-		    (nitems == 1) && (bytes_after == 0)) {
-			/* blast it away */
-			XKillClient(dpy, (XID) * pm);
-			XFree((caddr_t) pm);
-		} else if (actual_type != None) {
-			fprintf(stderr, "%s: warning: invalid format encountered for property %s\n",
-				"xli", RETAIN_PROP_NAME);
-		}
+        nitems = sizeof(Pixmap)/4;
+        returncode = XGetWindowProperty(dpy, w, atom,
+                                        0, nitems, 1/*delete*/,
+                                        XA_PIXMAP, &actual_type,
+                                        &format, &nitems,
+                                        &bytes_after, &charpm);
+        if (returncode != Success) {
+            if (globals.verbose)
+                fprintf(stderr, "failed to look for %s with return code %i.\n",
+                        RETAIN_PROP_NAME, returncode);
+            return;
+        }
+
+        /* Check if the property was found */
+        if (actual_type == None) {
+            if (globals.verbose)
+                fprintf(stderr, "didn't find evidence of prior run.\n");
+            return;
+        }
+
+        /* Make sure the dummy value is still present */
+        if (actual_type != XA_PIXMAP) {
+            if (globals.verbose)
+                fprintf(stderr, "found wrong data type - skipped.\n");
+            return;
+        }
+
+        /* Check size, in case we're a different architecture */
+        if ((nitems != sizeof(Pixmap)/4) ||
+            (format != 32) ||
+            (bytes_after != 0)) {
+            if (globals.verbose)
+                fprintf(stderr, "saw wrong %li / word size %i / architecture %li.\n",
+                        bytes_after, format, nitems);
+            return;
+        }
+
+        /* blast it away */
+        pm = (Pixmap*) charpm;
+        XKillClient(dpy, (XID) *pm);
+        XFree(charpm);
 }
 
 /* this returns the root window for DECWindows servers.  this is right
@@ -160,23 +182,22 @@ void imageOnRoot(DisplayInfo * dinfo, Image * image, ImageOptions * options)
 		for (i = 0; i < numChildren; i++) {
 			Atom actual_type;
 			int actual_format;
-			long nitems, bytesafter;
-			Window *newRoot = NULL;
-
-			if (XGetWindowProperty(disp, children[i], __SWM_VROOT,
-					0, 1, FALSE, XA_WINDOW, &actual_type,
-					&actual_format,
-					(unsigned long *) &nitems,
-					(unsigned long *) &bytesafter,
-					(unsigned char **) &newRoot)
-					== Success && newRoot) {
-				root = *newRoot;
-				break;
+                        unsigned long nitems, bytesafter;
+                        unsigned char *newRoot = 0;
+
+                        if ((XGetWindowProperty (disp, children[i], __SWM_VROOT,0,1,
+                                                 False, XA_WINDOW,
+                                                 &actual_type, &actual_format,
+                                                 &nitems, &bytesafter, &newRoot)
+                             == Success) &&
+                            newRoot) {
+                            root = *((Window*) newRoot);
+                            break;
 			}
 		}
 		XFree((caddr_t) children);
 	}
-	freePrevious(disp, root);
+        freePrevious(disp, root);
 
 	if (!(ximageinfo = imageToXImage(disp, scrn,
 			DefaultVisual(disp, scrn),
 
дизайн и разработка: Vladimir Lettiev aka crux © 2004-2005, Andrew Avramenko aka liks © 2007-2008
текущий майнтейнер: Michael Shigorin