wsmouse(4) doesn't free the memory allocated for the wstpad state
when an external touchpad is being unplugged.  This patch fixes
the leak.

OK?


Index: wsmouse.c
===================================================================
RCS file: /cvs/src/sys/dev/wscons/wsmouse.c,v
retrieving revision 1.66
diff -u -p -r1.66 wsmouse.c
--- wsmouse.c   29 Jul 2020 05:53:52 -0000      1.66
+++ wsmouse.c   20 Mar 2021 22:23:35 -0000
@@ -1712,5 +1712,8 @@ wsmouse_input_reset(struct wsmouseinput
 void
 wsmouse_input_cleanup(struct wsmouseinput *input)
 {
+       if (input->tp != NULL)
+               wstpad_cleanup(input);
+
        free_mt_slots(input);
 }
Index: wsmouseinput.h
===================================================================
RCS file: /cvs/src/sys/dev/wscons/wsmouseinput.h,v
retrieving revision 1.14
diff -u -p -r1.14 wsmouseinput.h
--- wsmouseinput.h      19 Aug 2019 21:19:38 -0000      1.14
+++ wsmouseinput.h      20 Mar 2021 22:23:35 -0000
@@ -193,6 +193,7 @@ void wstpad_compat_convert(struct wsmous
 void wstpad_init_deceleration(struct wsmouseinput *);
 int wstpad_configure(struct wsmouseinput *);
 void wstpad_reset(struct wsmouseinput *);
+void wstpad_cleanup(struct wsmouseinput *);

 int wstpad_get_param(struct wsmouseinput *, int, int *);
 int wstpad_set_param(struct wsmouseinput *, int, int);
Index: wstpad.c
===================================================================
RCS file: /cvs/src/sys/dev/wscons/wstpad.c,v
retrieving revision 1.27
diff -u -p -r1.27 wstpad.c
--- wstpad.c    3 Mar 2021 19:44:37 -0000       1.27
+++ wstpad.c    20 Mar 2021 22:23:35 -0000
@@ -1670,6 +1670,19 @@ wstpad_reset(struct wsmouseinput *input)
        }
 }

+void
+wstpad_cleanup(struct wsmouseinput *input)
+{
+       struct wstpad *tp = input->tp;
+       int slots;
+
+       timeout_del(&tp->tap.to);
+       slots = imax(input->mt.num_slots, 1);
+       free(tp->tpad_touches, M_DEVBUF, slots * sizeof(struct tpad_touch));
+       free(tp, M_DEVBUF, sizeof(struct wstpad));
+       input->tp = NULL;
+}
+
 int
 wstpad_set_param(struct wsmouseinput *input, int key, int val)
 {

Reply via email to