Browse Source

pen: fix leak caused by pen subsystem

Anonymous Maarten 1 year ago
parent
commit
a197efe3a7
4 changed files with 20 additions and 0 deletions
  1. 1 0
      src/events/SDL_mouse.c
  2. 13 0
      src/events/SDL_pen.c
  3. 5 0
      src/events/SDL_pen_c.h
  4. 1 0
      test/testautomation_pen.c

+ 1 - 0
src/events/SDL_mouse.c

@@ -898,6 +898,7 @@ void SDL_QuitMouse(void)
     }
     SDL_SetRelativeMouseMode(SDL_FALSE);
     SDL_ShowCursor();
+    SDL_PenQuit();
 
     if (mouse->def_cursor) {
         SDL_SetDefaultCursor(NULL);

+ 13 - 0
src/events/SDL_pen.c

@@ -829,6 +829,19 @@ void SDL_PenInit(void)
 #endif
 }
 
+void SDL_PenQuit(void)
+{
+    SDL_DelHintCallback(SDL_HINT_PEN_NOT_MOUSE,
+                        SDL_PenUpdateHint, &pen_mouse_emulation_mode);
+
+    SDL_DelHintCallback(SDL_HINT_PEN_DELAY_MOUSE_BUTTON,
+                        SDL_PenUpdateHint, &pen_delay_mouse_button_mode);
+#ifndef SDL_THREADS_DISABLED
+    SDL_DestroyMutex(SDL_pen_access_lock);
+    SDL_pen_access_lock = NULL;
+#endif
+}
+
 SDL_bool SDL_PenPerformHitTest(void)
 {
     return pen_mouse_emulation_mode == PEN_MOUSE_EMULATE;

+ 5 - 0
src/events/SDL_pen_c.h

@@ -331,6 +331,11 @@ extern int SDL_SendPenWindowEvent(Uint64 timestamp, SDL_PenID instance_id, SDL_W
  */
 extern void SDL_PenInit(void);
 
+/**
+ * De-initialises the pen subsystem.
+ */
+extern void SDL_PenQuit(void);
+
 #endif /* SDL_pen_c_h_ */
 
 /* vi: set ts=4 sw=4 expandtab: */

+ 1 - 0
test/testautomation_pen.c

@@ -54,6 +54,7 @@
 #define SDL_SendPenWindowEvent       SDL_SUT_SendPenWindowEvent
 #define SDL_PenPerformHitTest        SDL_SUT_PenPerformHitTest
 #define SDL_PenInit                  SDL_SUT_PenInit
+#define SDL_PenQuit                  SDL_SUT_PenQuit
 
 /* ================= Mock API ================== */