Commit c0f6fc4
committed
tasks/autodetect: replace needless strdup of device_info.name with stack buffer
input_autoconfigure_connect_handler has a block that temporarily
overwrites autoconfig_handle->device_info.name with a fallback-driver
name (e.g. 'XInput Controller' / 'Standard Gamepad'), re-runs the
scan, then restores the original. It saved the original name via
char *name_backup = strdup(autoconfig_handle->device_info.name);
and free()d it after the restore. Two problems with that:
1. device_info.name is a fixed-size char[128] ivar on
input_device_info_t (input/input_driver.h:334), not a heap
pointer. Heap allocation and free are unnecessary; a stack
buffer sized from sizeof(device_info.name) does the job with
zero allocator traffic.
2. strdup returning NULL was not checked. If the malloc failed,
the subsequent strlcpy(device_info.name, name_backup, ...)
would call strlcpy with src=NULL, which is undefined behaviour
and on glibc / Bionic / musl will segfault inside strlen.
Fix: declare 'char name_backup[sizeof(autoconfig_handle->device_info.name)]'
on the stack right where the old strdup was, copy into it with
strlcpy, and drop the manual free / NULL-assign at the end of the
block. No heap allocation, no OOM failure mode.
Thread-safety: unchanged. input_autoconfigure_connect_handler runs
on the task worker thread; device_info is owned by autoconfig_handle
which is the task's state struct. The name_backup buffer is a
short-lived local; nothing else accesses it.
Scope: this runs once per input device connection (low frequency
event), so the fix is correctness-focused, not a performance
improvement. Same pattern as the savestate-thumbnail fixes in
93449d3 / 741ead4 (needless strdup of fixed-size char[] ivars).1 parent aeaaa23 commit c0f6fc4
1 file changed
Lines changed: 12 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
756 | 756 | | |
757 | 757 | | |
758 | 758 | | |
759 | | - | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
760 | 771 | | |
761 | 772 | | |
762 | 773 | | |
| |||
771 | 782 | | |
772 | 783 | | |
773 | 784 | | |
774 | | - | |
775 | | - | |
776 | | - | |
777 | 785 | | |
778 | 786 | | |
779 | 787 | | |
| |||
0 commit comments