[Xfce4-commits] <xfce4-settings:master> Fix segfault if pointer has no feedback states and free memory.

Nick Schermer noreply at xfce.org
Sat May 7 10:20:01 CEST 2011


Updating branch refs/heads/master
         to 1badff8a32e9d931ca266f37acf3eed48db90e46 (commit)
       from 3bba3dea62990329e8d5bf662a6b389fa70e7559 (commit)

commit 1badff8a32e9d931ca266f37acf3eed48db90e46
Author: Nick Schermer <nick at xfce.org>
Date:   Sat May 7 09:18:29 2011 +0200

    Fix segfault if pointer has no feedback states and free memory.

 dialogs/mouse-settings/main.c |   33 ++++++++++++++++-----------------
 1 files changed, 16 insertions(+), 17 deletions(-)

diff --git a/dialogs/mouse-settings/main.c b/dialogs/mouse-settings/main.c
index b00fc72..941670d 100644
--- a/dialogs/mouse-settings/main.c
+++ b/dialogs/mouse-settings/main.c
@@ -572,7 +572,7 @@ mouse_settings_device_selection_changed (GtkTreeSelection *selection,
     gint               nbuttons;
     Display           *xdisplay;
     XDevice           *device;
-    XFeedbackState    *states;
+    XFeedbackState    *states, *pt;
     gint               nstates;
     XPtrFeedbackState *state;
     gint               i;
@@ -634,28 +634,27 @@ mouse_settings_device_selection_changed (GtkTreeSelection *selection,
 
             /* get the feedback states for this device */
             states = XGetFeedbackControl (xdisplay, device, &nstates);
-
-            /* intial values */
-            acceleration = threshold = -1;
-
-            /* get the pointer feedback class */
-            for (i = 0; i < nstates; i++)
+            if (states != NULL)
             {
-                if (states->class == PtrFeedbackClass)
+                /* get the pointer feedback class */
+                for (pt = states, i = 0; i < nstates; i++)
                 {
-                    /* get the state */
-                    state = (XPtrFeedbackState *) states;
+                    if (pt->class == PtrFeedbackClass)
+                    {
+                        /* get the state */
+                        state = (XPtrFeedbackState *) pt;
+                        acceleration = (gdouble) state->accelNum / (gdouble) state->accelDenom;
+                        threshold = state->threshold;
 
-                    /* set values */
-                    acceleration = (gdouble) state->accelNum / (gdouble) state->accelDenom;
-                    threshold = state->threshold;
+                        /* done */
+                        break;
+                    }
 
-                    /* done */
-                    break;
+                    /* advance the offset */
+                    pt = (XFeedbackState *) ((gchar *) pt + pt->length);
                 }
 
-                /* advance the offset */
-                states = (XFeedbackState *) ((gchar *) states + states->length);
+                XFreeFeedbackList (states);
             }
 
             /* close the device */



More information about the Xfce4-commits mailing list