mousetweaks r442 - in trunk: . src



Author: gerdk
Date: Mon Mar  2 12:29:48 2009
New Revision: 442
URL: http://svn.gnome.org/viewvc/mousetweaks?rev=442&view=rev

Log:
2009-03-02  Gerd Kohlberger  <gerdk svn gnome org>

	Fix possible crash if an accessible object is defunct.
 
	* src/mt.c: add null check
	* src/mt-accessible.c: check if child is valid



Modified:
   trunk/ChangeLog
   trunk/src/mt-accessible.c
   trunk/src/mt-main.c

Modified: trunk/src/mt-accessible.c
==============================================================================
--- trunk/src/mt-accessible.c	(original)
+++ trunk/src/mt-accessible.c	Mon Mar  2 12:29:48 2009
@@ -17,9 +17,6 @@
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <glib.h>
-#include <cspi/spi.h>
-
 #include "mt-accessible.h"
 
 #define MAX_SEARCHES 200
@@ -138,32 +135,37 @@
     Accessible *a;
     gboolean found;
     gint n_searches;
-    glong n, i;
+    glong i;
 
     g_return_val_if_fail (accessible != NULL, NULL);
 
     queue = g_queue_new ();
     g_queue_push_head (queue, accessible);
     Accessible_ref (accessible);
+
+    a = NULL;
     n_searches = 0;
+    found = FALSE;
 
     if (type == MT_SEARCH_TYPE_BREADTH) {
 	/* (reverse) breadth first search - queue FIFO */
 	while (!g_queue_is_empty (queue)) {
 	    a = g_queue_pop_tail (queue);
 
+	    if (!a)
+		continue;
+
 	    if ((found = (eval) (a, data)))
 		break;
 	    else if (++n_searches >= MAX_SEARCHES) {
 		Accessible_unref (a);
 		break;
 	    }
-	    if ((push) (a, data)) {
-		n = Accessible_getChildCount (a);
-		for (i = 0; i < n; ++i)
-		    g_queue_push_head (queue,
-				       Accessible_getChildAtIndex (a, i));
-	    }
+
+	    if ((push) (a, data))
+		for (i = 0; i < Accessible_getChildCount (a); ++i)
+		    g_queue_push_head (queue, Accessible_getChildAtIndex (a, i));
+
 	    Accessible_unref (a);
 	}
     }
@@ -172,29 +174,30 @@
 	while (!g_queue_is_empty (queue)) {
 	    a = g_queue_pop_head (queue);
 
+	    if (!a)
+		continue;
+
 	    if ((found = (eval) (a, data)))
 		break;
 	    else if (++n_searches >= MAX_SEARCHES) {
 		Accessible_unref (a);
 		break;
 	    }
-	    if ((push) (a, data)) {
-		n = Accessible_getChildCount (a);
-		for (i = 0; i < n; ++i)
-		    g_queue_push_head (queue,
-				       Accessible_getChildAtIndex (a, i));
-	    }
+
+	    if ((push) (a, data))
+		for (i = 0; i < Accessible_getChildCount (a); ++i)
+		    g_queue_push_head (queue, Accessible_getChildAtIndex (a, i));
+
 	    Accessible_unref (a);
 	}
     }
-    else {
+    else
 	g_warning ("Unknown search type.");
-	found = FALSE;
-    }
+
     g_queue_foreach (queue, (GFunc) Accessible_unref, NULL);
     g_queue_free (queue);
 
-    return found ? a : NULL; 
+    return found ? a : NULL;
 }
 
 Accessible *

Modified: trunk/src/mt-main.c
==============================================================================
--- trunk/src/mt-main.c	(original)
+++ trunk/src/mt-main.c	Mon Mar  2 12:29:48 2009
@@ -329,17 +329,18 @@
 static gboolean
 eval_func (Accessible *a, gpointer data)
 {
-    gboolean found;
-    char *name;
+    gchar *name;
+    gboolean found = FALSE;
 
     name = Accessible_getName (a);
-    found = g_str_equal (name, "Window List");
-    SPI_freeString (name);
-
+    if (name) {
+	found = g_str_equal (name, "Window List");
+	SPI_freeString (name);
+    }
     return found;
 }
 
-static gboolean 
+static gboolean
 push_func (Accessible *a, gpointer data)
 {
     MTClosure *mt = data;



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