diff --git a/include/QF/input/binding.h b/include/QF/input/binding.h index 02363abe5..86fde3548 100644 --- a/include/QF/input/binding.h +++ b/include/QF/input/binding.h @@ -365,6 +365,7 @@ struct IE_event_s; int IN_Binding_HandleEvent (const struct IE_event_s *ie_event); void IN_Binding_Activate (void); void IN_Binding_Init (void); +void IN_Binding_Shutdown (void); struct plitem_s; void IN_Binding_SaveConfig (struct plitem_s *config); void IN_Binding_LoadConfig (struct plitem_s *config); diff --git a/include/QF/input/imt.h b/include/QF/input/imt.h index 5f3f8c2d3..5009a57da 100644 --- a/include/QF/input/imt.h +++ b/include/QF/input/imt.h @@ -130,6 +130,7 @@ void IMT_BindButton (imt_t *imt, int button, const char *binding); qboolean IMT_ProcessAxis (int axis, int value); qboolean IMT_ProcessButton (int button, int state); void IMT_Init (void); +void IMT_Shutdown (void); struct plitem_s; void IMT_SaveConfig (struct plitem_s *config); void IMT_SaveAxisConfig (struct plitem_s *axes, int axis_ind, int dev_axis); diff --git a/libs/input/evdev/inputlib.c b/libs/input/evdev/inputlib.c index 02a3611f8..1ac7d15ab 100644 --- a/libs/input/evdev/inputlib.c +++ b/libs/input/evdev/inputlib.c @@ -191,7 +191,6 @@ check_device (const char *path) { device_t *dev; int fd; - dstring_t *buff = dstring_newstr (); fd = open (path, O_RDWR); if (fd == -1) @@ -208,9 +207,11 @@ check_device (const char *path) dev->path = strdup (path); dev->fd = fd; + dstring_t *buff = dstring_newstr (); dev->name = strdup (get_string (fd, EVIOCGNAME, buff)); dev->phys = strdup (get_string (fd, EVIOCGPHYS, buff)); dev->uniq = strdup (get_string (fd, EVIOCGUNIQ, buff)); + dstring_delete (buff); setup_buttons(dev); setup_axes(dev); diff --git a/libs/input/in_axis.c b/libs/input/in_axis.c index ccf061eeb..303cc75ea 100644 --- a/libs/input/in_axis.c +++ b/libs/input/in_axis.c @@ -93,9 +93,15 @@ IN_AxisRemoveListener (in_axis_t *axis, axis_listener_t listener, void *data) } } +static void +in_axis_shutdown (void *data) +{ + Hash_DelTable (axis_tab); +} static void __attribute__((constructor)) in_axis_init (void) { axis_tab = Hash_NewTable (127, axis_get_key, axis_free, 0, 0); + Sys_RegisterShutdown (in_axis_shutdown, 0); } diff --git a/libs/input/in_binding.c b/libs/input/in_binding.c index a8ea9d72f..562ac7636 100644 --- a/libs/input/in_binding.c +++ b/libs/input/in_binding.c @@ -788,6 +788,19 @@ IN_Binding_Init (void) } } +void +IN_Binding_Shutdown () +{ + for (in_devbindings_t *db = devbindings_list; db; db = db->next) { + clear_connection (db); + } + for (unsigned i = 0; i < devbindings._size; i++) { + free (devbindings._map[i]); + } + free (devbindings._map); + DARRAY_CLEAR (&known_devices); +} + void IN_Binding_SaveConfig (plitem_t *config) { diff --git a/libs/input/in_button.c b/libs/input/in_button.c index 15d28160d..97e4339ad 100644 --- a/libs/input/in_button.c +++ b/libs/input/in_button.c @@ -62,7 +62,12 @@ button_get_key (const void *b, void *data) static void button_free (void *b, void *data) { - free (b); + regbutton_t *rb = b; + if (rb->button->listeners) { + DARRAY_CLEAR (rb->button->listeners); + free (rb->button->listeners); + } + free (rb); } static void @@ -222,8 +227,15 @@ IN_ButtonRemoveListener (in_button_t *button, button_listener_t listener, } } +static void +in_button_shutdown (void *data) +{ + Hash_DelTable (button_tab); +} + static void __attribute__((constructor)) in_button_init (void) { button_tab = Hash_NewTable (127, button_get_key, button_free, 0, 0); + Sys_RegisterShutdown (in_button_shutdown, 0); } diff --git a/libs/input/in_common.c b/libs/input/in_common.c index 65d53637f..9d9920641 100644 --- a/libs/input/in_common.c +++ b/libs/input/in_common.c @@ -539,6 +539,11 @@ IN_shutdown (void *data) rd->driver.shutdown (rd->data); } } + IN_Binding_Shutdown (); + IMT_Shutdown (); + + DARRAY_CLEAR (&in_drivers); + DARRAY_CLEAR (&in_devices); } void diff --git a/libs/input/in_evdev.c b/libs/input/in_evdev.c index 73f6cfe77..af49d2677 100644 --- a/libs/input/in_evdev.c +++ b/libs/input/in_evdev.c @@ -76,6 +76,11 @@ static void in_evdev_shutdown (void *data) { inputlib_close (); + + for (unsigned i = 0; i < devmap._size; i++) { + free (devmap._map[i]); + } + free (devmap._map); } static void diff --git a/libs/input/in_event.c b/libs/input/in_event.c index caa9e9ccb..e5240f3b9 100644 --- a/libs/input/in_event.c +++ b/libs/input/in_event.c @@ -120,3 +120,16 @@ IE_Get_Focus (void) { return focus; } + +static void +in_event_shutdown (void *data) +{ + DARRAY_CLEAR (&ie_handlers); +} + +static void __attribute__((constructor)) +in_event_init (void) +{ + //FIXME see in_evdev + Sys_RegisterShutdown (in_event_shutdown, 0); +} diff --git a/libs/input/in_imt.c b/libs/input/in_imt.c index 435315d01..5df45d7b8 100644 --- a/libs/input/in_imt.c +++ b/libs/input/in_imt.c @@ -835,6 +835,8 @@ imt_drop_all_f (void) for (size_t i = 0; i < imt->button_bindings.size; i++) { free_button_binding (imt->button_bindings.a[i]); } + DARRAY_CLEAR (&imt->axis_bindings); + DARRAY_CLEAR (&imt->button_bindings); free ((char *) imt->name); free (imt); } @@ -940,6 +942,19 @@ IMT_Init (void) } } +void +IMT_Shutdown (void) +{ + imt_drop_all_f (); + Hash_DelTable (recipe_tab); + + delete_memsuper (binding_mem); + binding_mem = 0; + DARRAY_CLEAR (&axis_blocks); + DARRAY_CLEAR (&button_blocks); + DARRAY_CLEAR (&in_contexts); +} + void IMT_SaveConfig (plitem_t *config) { @@ -1078,8 +1093,8 @@ IMT_SaveButtonConfig (plitem_t *buttons, int button_ind, int dev_button) void IMT_LoadConfig (plitem_t *config) { - imt_reset_blocks (); imt_drop_all_f (); + imt_reset_blocks (); plitem_t *ctx_list = PL_ObjectForKey (config, "contexts"); if (PL_Type (ctx_list) != QFArray) {