mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-10-05 09:26:25 +00:00
Introduce formal policy for APIs that return strings.
This declares that any `const char *` returned from SDL is owned by SDL, and promises to be valid _at least_ until the next time the event queue runs, or SDL_Quit() is called, even if the thing that owns the string gets destroyed or changed before then. This is noted in the headers as "the SDL_GetStringRule", so this will both be greppable to find a detailed explaination in docs/README-strings.md and wikiheaders will automatically turn it into a link we can point at the appropriate documentation. Fixes #9902. (and several FIXMEs, both known and yet-undocumented.)
This commit is contained in:
@@ -100,7 +100,7 @@ const char *SDL_GetHapticInstanceName(SDL_HapticID instance_id)
|
||||
if (SDL_GetHapticIndex(instance_id, &device_index)) {
|
||||
name = SDL_SYS_HapticName(device_index);
|
||||
}
|
||||
return name;
|
||||
return name ? SDL_FreeLater(SDL_strdup(name)) : NULL;
|
||||
}
|
||||
|
||||
SDL_Haptic *SDL_OpenHaptic(SDL_HapticID instance_id)
|
||||
@@ -338,7 +338,7 @@ void SDL_CloseHaptic(SDL_Haptic *haptic)
|
||||
}
|
||||
|
||||
/* Free the data associated with this device */
|
||||
SDL_free(haptic->name);
|
||||
SDL_FreeLater(haptic->name); // this pointer is handed to the app in SDL_GetHapticName()
|
||||
SDL_free(haptic);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user