Fix crash on controller hotplug on linux. CR: Sam
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
diff --git a/src/haptic/linux/SDL_syshaptic.c b/src/haptic/linux/SDL_syshaptic.c
index ab0a570..659252b 100644
--- a/src/haptic/linux/SDL_syshaptic.c
+++ b/src/haptic/linux/SDL_syshaptic.c
@@ -465,7 +465,7 @@ SDL_SYS_HapticOpen(SDL_Haptic * haptic)
}
/* Set the fname. */
- haptic->hwdata->fname = item->fname;
+ haptic->hwdata->fname = SDL_strdup( item->fname );
return 0;
}
@@ -542,11 +542,12 @@ SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
/* Find the joystick in the haptic list. */
for (item = SDL_hapticlist; item; item = item->next) {
if (SDL_strcmp(item->fname, joystick->hwdata->fname) == 0) {
- haptic->index = device_index;
break;
}
++device_index;
}
+ haptic->index = device_index;
+
if (device_index >= MAX_HAPTICS) {
return SDL_SetError("Haptic: Joystick doesn't have Haptic capabilities");
}
@@ -561,7 +562,8 @@ SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
return -1;
}
- haptic->hwdata->fname = item->fname;
+ haptic->hwdata->fname = SDL_strdup( joystick->hwdata->fname );
+
return 0;
}
@@ -583,6 +585,7 @@ SDL_SYS_HapticClose(SDL_Haptic * haptic)
close(haptic->hwdata->fd);
/* Free */
+ SDL_free(haptic->hwdata->fname);
SDL_free(haptic->hwdata);
haptic->hwdata = NULL;
}