diff --git a/daemon/x52d_mouse_handler.c b/daemon/x52d_mouse_handler.c index 049471f..ea9749f 100644 --- a/daemon/x52d_mouse_handler.c +++ b/daemon/x52d_mouse_handler.c @@ -31,7 +31,7 @@ static volatile libx52io_report new_report; static int report_button_change(vkm_mouse_button button, int index) { - vkm_result rc; + vkm_result rc = VKM_ERROR_NO_CHANGE; bool old_button = old_report.button[index]; bool new_button = new_report.button[index]; vkm_button_state state; @@ -50,7 +50,7 @@ static int report_button_change(vkm_mouse_button button, int index) static int report_wheel(void) { - vkm_result rc; + vkm_result rc = VKM_ERROR_NO_CHANGE; int wheel = 0; bool scroll_up = new_report.button[LIBX52IO_BTN_MOUSE_SCROLL_UP]; bool scroll_dn = new_report.button[LIBX52IO_BTN_MOUSE_SCROLL_DN]; diff --git a/libx52/x52_core.c b/libx52/x52_core.c index c742916..c6f84d8 100644 --- a/libx52/x52_core.c +++ b/libx52/x52_core.c @@ -231,6 +231,8 @@ int libx52_init(libx52_device **dev) void libx52_exit(libx52_device *dev) { + volatile unsigned char *vp; + if (!dev) { return; } @@ -239,7 +241,10 @@ void libx52_exit(libx52_device *dev) libusb_exit(dev->ctx); /* Clear the memory to prevent reuse */ - memset(dev, 0, sizeof(*dev)); + vp = (volatile unsigned char *)dev; + for (int i = 0; i < sizeof(*dev); i++) { + vp[i] = (unsigned char)0; + } free(dev); } diff --git a/vkm/vkm_linux_evdev.c b/vkm/vkm_linux_evdev.c index 5f0d9c3..02cba9c 100644 --- a/vkm/vkm_linux_evdev.c +++ b/vkm/vkm_linux_evdev.c @@ -218,9 +218,7 @@ error: void vkm_exit(vkm_context *ctx) { - char *name; - struct libevdev_uinput *uidev; - struct libevdev *dev; + volatile unsigned char *vp; if (ctx == NULL) { return; @@ -228,20 +226,20 @@ void vkm_exit(vkm_context *ctx) (void)vkm_reset(ctx); - dev = ctx->dev; - uidev = ctx->uidev; - name = ctx->name; + free(ctx->name); - memset(ctx, 0, sizeof(*ctx)); - - free(name); - - if (uidev) { - libevdev_uinput_destroy(uidev); + if (ctx->uidev) { + libevdev_uinput_destroy(ctx->uidev); } - if (dev) { - libevdev_free(dev); + if (ctx->dev) { + libevdev_free(ctx->dev); + } + + /* Clear the memory to prevent reuse */ + vp = (volatile unsigned char *)ctx; + for (int i = 0; i < sizeof(*ctx); i++) { + vp[i] = (unsigned char)0; } free(ctx);