Fix crash on controller hotplug on linux.
authorSam Lantinga <slouken@libsdl.org>
Wed, 30 Sep 2015 15:38:30 -0700
changeset 9883 48cf7d652118
parent 9882 ddcf564c3fc8
child 9884 26b595dea221
Fix crash on controller hotplug on linux. CR: Sam
src/haptic/linux/SDL_syshaptic.c
--- a/src/haptic/linux/SDL_syshaptic.c	Wed Sep 30 15:38:18 2015 -0700
+++ b/src/haptic/linux/SDL_syshaptic.c	Wed Sep 30 15:38:30 2015 -0700
@@ -465,7 +465,7 @@
     }
 
     /* Set the fname. */
-    haptic->hwdata->fname = item->fname;
+    haptic->hwdata->fname = SDL_strdup( item->fname );
     return 0;
 }
 
@@ -542,11 +542,12 @@
     /* 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 @@
         return -1;
     }
 
-    haptic->hwdata->fname = item->fname;
+    haptic->hwdata->fname = SDL_strdup( joystick->hwdata->fname );
+
     return 0;
 }
 
@@ -583,6 +585,7 @@
         close(haptic->hwdata->fd);
 
         /* Free */
+        SDL_free(haptic->hwdata->fname);
         SDL_free(haptic->hwdata);
         haptic->hwdata = NULL;
     }