Fixed bug 2418 - Structure SDL_gestureTouch leaking Leonardo Structure SDL_gestureTouch gets reallocated for every new added gesture but its never freed. Proposed patch add the function SDL_GestureQuit() that takes care of doing that and gets called when TouchQuit is called. Gabriel Jacobo Thanks for the patch. I think it needs a bit of extra work though, looking at the code in SDL_gesture.c , I see that SDL_numGestureTouches only goes up, I think the right fix here involves adding SDL_GestureDelTouch (hooked into SDL_DelTouch) as well as SDL_GestureQuit (as you posted in your patch).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
diff --git a/src/events/SDL_gesture.c b/src/events/SDL_gesture.c
index 8b21066..e8477ac 100644
--- a/src/events/SDL_gesture.c
+++ b/src/events/SDL_gesture.c
@@ -101,6 +101,12 @@ int SDL_RecordGesture(SDL_TouchID touchId)
return (touchId < 0);
}
+void SDL_GestureQuit()
+{
+ SDL_free(SDL_gestureTouch);
+ SDL_gestureTouch = NULL;
+}
+
static unsigned long SDL_HashDollar(SDL_FloatPoint* points)
{
unsigned long hash = 5381;
@@ -457,6 +463,28 @@ int SDL_GestureAddTouch(SDL_TouchID touchId)
return 0;
}
+int SDL_GestureDelTouch(SDL_TouchID touchId)
+{
+ int i;
+ for (i = 0; i < SDL_numGestureTouches; i++) {
+ if (SDL_gestureTouch[i].id == touchId) {
+ break;
+ }
+ }
+
+ if (i == SDL_numGestureTouches) {
+ /* not found */
+ return -1;
+ }
+
+ SDL_free(SDL_gestureTouch[i].dollarTemplate);
+ SDL_zero(SDL_gestureTouch[i]);
+
+ SDL_numGestureTouches--;
+ SDL_gestureTouch[i] = SDL_gestureTouch[SDL_numGestureTouches];
+ return 0;
+}
+
static SDL_GestureTouch * SDL_GetGestureTouch(SDL_TouchID id)
{
int i;
diff --git a/src/events/SDL_gesture_c.h b/src/events/SDL_gesture_c.h
index bce812b..ab588b0 100644
--- a/src/events/SDL_gesture_c.h
+++ b/src/events/SDL_gesture_c.h
@@ -24,9 +24,12 @@
#define SDL_gesture_c_h_
extern int SDL_GestureAddTouch(SDL_TouchID touchId);
+extern int SDL_GestureDelTouch(SDL_TouchID touchId);
extern void SDL_GestureProcessEvent(SDL_Event* event);
+extern void SDL_GestureQuit(void);
+
#endif /* SDL_gesture_c_h_ */
/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/events/SDL_touch.c b/src/events/SDL_touch.c
index 92e76f2..39a765a 100644
--- a/src/events/SDL_touch.c
+++ b/src/events/SDL_touch.c
@@ -352,6 +352,9 @@ SDL_DelTouch(SDL_TouchID id)
SDL_num_touch--;
SDL_touchDevices[index] = SDL_touchDevices[SDL_num_touch];
+
+ /* Delete this touch device for gestures */
+ SDL_GestureDelTouch(id);
}
void
@@ -366,6 +369,7 @@ SDL_TouchQuit(void)
SDL_free(SDL_touchDevices);
SDL_touchDevices = NULL;
+ SDL_GestureQuit();
}
/* vi: set ts=4 sw=4 expandtab: */