Skip to content

Commit

Permalink
[Fix] Fix crash (and memleak) with sound with DYNAMIC_LOAD.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarod42 committed Aug 1, 2024
1 parent 02fa231 commit 1d516c1
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/sound/sound_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,13 @@ sdl2::ChunkPtr LoadSample(const std::string &name)
*/
void FreeSample(Mix_Chunk *sample)
{
if (sample == nullptr) {
return;
}
#ifdef DYNAMIC_LOAD
if (sample->allocated == NotYetLoadedMagic) {
free(sample->abuf);
SDL_free(sample);
return;
}
#endif
Expand All @@ -494,8 +499,7 @@ static int PlaySample(Mix_Chunk *sample, Origin *origin, void (*callback)(int ch
if (sample->allocated == NotYetLoadedMagic) {
char *name = (char*)(sample->abuf);
if (auto loadedSample = ForceLoadSample(name)) {
memcpy(sample, loadedSample.get(), sizeof(Mix_Chunk));
free(name);
std::swap(*sample, *loadedSample);
} else {
return -1;
}
Expand Down

0 comments on commit 1d516c1

Please sign in to comment.