emacs-diffs
[Top][All Lists]
Advanced

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

master 9369e4242f: Work around rare crash when turning scroll wheel


From: Po Lu
Subject: master 9369e4242f: Work around rare crash when turning scroll wheel
Date: Thu, 22 Sep 2022 05:07:01 -0400 (EDT)

branch: master
commit 9369e4242fa51d53b05ce95842f124522289d8a3
Author: Po Lu <luangruo@yahoo.com>
Commit: Po Lu <luangruo@yahoo.com>

    Work around rare crash when turning scroll wheel
    
    * src/xterm.c (handle_one_xevent): Don't allow devices to be
    added twice handling hierarcy events.
---
 src/xterm.c | 44 ++++++++++++++++++++++++++++----------------
 1 file changed, 28 insertions(+), 16 deletions(-)

diff --git a/src/xterm.c b/src/xterm.c
index 97c070736c..6860ef2080 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -23000,24 +23000,36 @@ handle_one_xevent (struct x_display_info *dpyinfo,
                          any_changed = true;
                        }
 
-                     x_catch_errors (dpyinfo->display);
-                     info = XIQueryDevice (dpyinfo->display, 
hev->info[i].deviceid,
-                                           &ndevices);
-                     x_uncatch_errors ();
-
-                     if (info && info->enabled)
+                     /* Under unknown circumstances, multiple
+                        XIDeviceEnabled events are sent at once,
+                        causing the device to be duplicated.  Check
+                        that the device doesn't exist before adding
+                        it.  */
+
+                     if (!xi_device_from_id (dpyinfo,
+                                             hev->info[i].deviceid))
                        {
-                         dpyinfo->devices
-                           = xrealloc (dpyinfo->devices, (sizeof 
*dpyinfo->devices
-                                                          * 
++dpyinfo->num_devices));
-                         memset (dpyinfo->devices + dpyinfo->num_devices - 1,
-                                 0, sizeof *dpyinfo->devices);
-                         device = &dpyinfo->devices[dpyinfo->num_devices - 1];
-                         xi_populate_device_from_info (device, info);
-                       }
+                         x_catch_errors (dpyinfo->display);
+                         info = XIQueryDevice (dpyinfo->display,
+                                               hev->info[i].deviceid,
+                                               &ndevices);
+                         x_uncatch_errors ();
 
-                     if (info)
-                       XIFreeDeviceInfo (info);
+                         if (info && info->enabled)
+                           {
+                             dpyinfo->devices
+                               = xrealloc (dpyinfo->devices,
+                                           (sizeof *dpyinfo->devices
+                                            * ++dpyinfo->num_devices));
+                             memset (dpyinfo->devices + dpyinfo->num_devices - 
1,
+                                     0, sizeof *dpyinfo->devices);
+                             device = &dpyinfo->devices[dpyinfo->num_devices - 
1];
+                             xi_populate_device_from_info (device, info);
+                           }
+
+                         if (info)
+                           XIFreeDeviceInfo (info);
+                       }
                    }
                  else if (hev->info[i].flags & XIDeviceDisabled)
                    disabled[n_disabled++] = hev->info[i].deviceid;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]