Fix potential memory leak in vinput

In the export_store function, the error handling paths followed a
successful vinput_alloc_vdevice call are missing a corresponding
input_free_device call. Since vinput_alloc_vdevice internally calls
input_allocate_device, and input_register_device has not been called
yet, input_free_device should be used to properly free the allocated
input_device struct in this scenario[1].

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/input/input.c#n2094
This commit is contained in:
Bob Lee 2024-10-25 12:22:29 +08:00
parent 67713859df
commit b482911efb
No known key found for this signature in database
GPG Key ID: 0DA954476306EEFA

View File

@ -283,10 +283,12 @@ static ssize_t export_store(struct class *class, struct class_attribute *attr,
return len; return len;
fail_register_vinput: fail_register_vinput:
input_free_device(vinput->input);
device_unregister(&vinput->dev); device_unregister(&vinput->dev);
/* avoid calling vinput_destroy_vdevice() twice */ /* avoid calling vinput_destroy_vdevice() twice */
return err; return err;
fail_register: fail_register:
input_free_device(vinput->input);
vinput_destroy_vdevice(vinput); vinput_destroy_vdevice(vinput);
fail: fail:
return err; return err;