Fixed freeing strings created by strdup() with SDL_free().
authorPhilipp Wiesemann <philipp.wiesemann@arcor.de>
Tue, 28 Jun 2016 21:08:23 +0200
changeset 101871f0f8c95531d
parent 10186 6c8e53149f0c
child 10188 9cf58ba2b2ad
Fixed freeing strings created by strdup() with SDL_free().

This only worked on platforms where SDL_free() wraps free().
src/joystick/bsd/SDL_sysjoystick.c
src/joystick/haiku/SDL_haikujoystick.cc
src/video/wayland/SDL_waylandvideo.c
     1.1 --- a/src/joystick/bsd/SDL_sysjoystick.c	Sun Jun 26 21:08:57 2016 +0200
     1.2 +++ b/src/joystick/bsd/SDL_sysjoystick.c	Tue Jun 28 21:08:23 2016 +0200
     1.3 @@ -179,7 +179,7 @@
     1.4  
     1.5          SDL_snprintf(s, SDL_arraysize(s), "/dev/uhid%d", i);
     1.6  
     1.7 -        joynames[SDL_SYS_numjoysticks] = strdup(s);
     1.8 +        joynames[SDL_SYS_numjoysticks] = SDL_strdup(s);
     1.9  
    1.10          if (SDL_SYS_JoystickOpen(&nj, SDL_SYS_numjoysticks) == 0) {
    1.11              SDL_SYS_JoystickClose(&nj);
    1.12 @@ -193,7 +193,7 @@
    1.13          SDL_snprintf(s, SDL_arraysize(s), "/dev/joy%d", i);
    1.14          fd = open(s, O_RDONLY);
    1.15          if (fd != -1) {
    1.16 -            joynames[SDL_SYS_numjoysticks++] = strdup(s);
    1.17 +            joynames[SDL_SYS_numjoysticks++] = SDL_strdup(s);
    1.18              close(fd);
    1.19          }
    1.20      }
    1.21 @@ -304,14 +304,14 @@
    1.22      }
    1.23      joy->hwdata = hw;
    1.24      hw->fd = fd;
    1.25 -    hw->path = strdup(path);
    1.26 +    hw->path = SDL_strdup(path);
    1.27      if (!SDL_strncmp(path, "/dev/joy", 8)) {
    1.28          hw->type = BSDJOY_JOY;
    1.29          joy->naxes = 2;
    1.30          joy->nbuttons = 2;
    1.31          joy->nhats = 0;
    1.32          joy->nballs = 0;
    1.33 -        joydevnames[device_index] = strdup("Gameport joystick");
    1.34 +        joydevnames[device_index] = SDL_strdup("Gameport joystick");
    1.35          goto usbend;
    1.36      } else {
    1.37          hw->type = BSDJOY_UHID;
    1.38 @@ -363,7 +363,7 @@
    1.39          str[i] = '\0';
    1.40          asprintf(&new_name, "%s @ %s", str, path);
    1.41          if (new_name != NULL) {
    1.42 -            free(joydevnames[SDL_SYS_numjoysticks]);
    1.43 +            SDL_free(joydevnames[SDL_SYS_numjoysticks]);
    1.44              joydevnames[SDL_SYS_numjoysticks] = new_name;
    1.45          }
    1.46      }
     2.1 --- a/src/joystick/haiku/SDL_haikujoystick.cc	Sun Jun 26 21:08:57 2016 +0200
     2.2 +++ b/src/joystick/haiku/SDL_haikujoystick.cc	Tue Jun 28 21:08:23 2016 +0200
     2.3 @@ -74,8 +74,8 @@
     2.4                  if (joystick.Open(name) != B_ERROR) {
     2.5                      BString stick_name;
     2.6                        joystick.GetControllerName(&stick_name);
     2.7 -                      SDL_joyport[SDL_SYS_numjoysticks] = strdup(name);
     2.8 -                      SDL_joyname[SDL_SYS_numjoysticks] = strdup(stick_name.String());
     2.9 +                      SDL_joyport[SDL_SYS_numjoysticks] = SDL_strdup(name);
    2.10 +                      SDL_joyname[SDL_SYS_numjoysticks] = SDL_strdup(stick_name.String());
    2.11                        SDL_SYS_numjoysticks++;
    2.12                        joystick.Close();
    2.13                  }
     3.1 --- a/src/video/wayland/SDL_waylandvideo.c	Sun Jun 26 21:08:57 2016 +0200
     3.2 +++ b/src/video/wayland/SDL_waylandvideo.c	Tue Jun 28 21:08:23 2016 +0200
     3.3 @@ -145,7 +145,7 @@
     3.4  {
     3.5      SDL_VideoDisplay *display = data;
     3.6  
     3.7 -    display->name = strdup(model);
     3.8 +    display->name = SDL_strdup(model);
     3.9      display->driverdata = output;
    3.10  }
    3.11