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:
parent
b1f3682216
commit
e23257307e
51 changed files with 262 additions and 123 deletions
|
@ -250,8 +250,7 @@ const char *SDL_GetSensorInstanceName(SDL_SensorID instance_id)
|
|||
}
|
||||
SDL_UnlockSensors();
|
||||
|
||||
/* FIXME: Really we should reference count this name so it doesn't go away after unlock */
|
||||
return name;
|
||||
return name ? SDL_FreeLater(SDL_strdup(name)) : NULL;
|
||||
}
|
||||
|
||||
SDL_SensorType SDL_GetSensorInstanceType(SDL_SensorID instance_id)
|
||||
|
@ -527,7 +526,7 @@ void SDL_CloseSensor(SDL_Sensor *sensor)
|
|||
}
|
||||
|
||||
/* Free the data associated with this sensor */
|
||||
SDL_free(sensor->name);
|
||||
SDL_FreeLater(sensor->name); // this pointer gets handed to the app by SDL_GetSensorName().
|
||||
SDL_free(sensor);
|
||||
}
|
||||
SDL_UnlockSensors();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue