Skip to content

Commit dbe92fe

Browse files
committed
Avoid use-after-free.
Reported by Dirk Meyer in bug 419. I made a very small change to the given patch only. git-svn-id: https://svn.code.sf.net/p/vice-emu/code/trunk@45927 379a1393-f5fb-40a0-bcee-ef074d9b53f7
1 parent 02cb976 commit dbe92fe

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

vice/src/arch/gtk3/joystickdrv/joystick_bsd.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -649,12 +649,14 @@ void joystick_arch_init(void)
649649
/* scan axes, buttons and hats */
650650
if (scan_inputs(joydev)) {
651651
/* OK: try to register */
652+
char *backup_name = lib_strdup(joydev->name);
653+
652654
if (!joystick_device_register(joydev)) {
653655
/* failure */
656+
/* joydev is already destroyed */
654657
log_warning(bsd_joy_log,
655658
"failed to register device %s (\"%s\")",
656-
joydev->node, joydev->name);
657-
joystick_device_free(joydev);
659+
node, backup_name);
658660
} else {
659661
priv = joydev->priv;
660662
/* allocate arrays for previous input states */
@@ -665,6 +667,7 @@ void joystick_arch_init(void)
665667
priv->prev_hats = lib_calloc((size_t)joydev->num_hats,
666668
sizeof *priv->prev_hats);
667669
}
670+
lib_free(backup_name);
668671
} else {
669672
/* failure while scanning: log and free invalid device */
670673
log_warning(bsd_joy_log,

0 commit comments

Comments
 (0)