Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed LoadSoundAlias() memory leak #3458

Merged
merged 1 commit into from
Oct 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/raudio.c
Original file line number Diff line number Diff line change
Expand Up @@ -928,21 +928,23 @@ Sound LoadSoundFromWave(Wave wave)
}

// Clone sound from existing sound data, clone does not own wave data
// Wave data must
// NOTE: Wave data must be unallocated manually and will be shared across all clones
Sound LoadSoundAlias(Sound source)
{
Sound sound = { 0 };

if (source.stream.buffer->data != NULL)
{
AudioBuffer* audioBuffer = LoadAudioBuffer(AUDIO_DEVICE_FORMAT, AUDIO_DEVICE_CHANNELS, AUDIO.System.device.sampleRate, source.frameCount, AUDIO_BUFFER_USAGE_STATIC);
AudioBuffer* audioBuffer = LoadAudioBuffer(AUDIO_DEVICE_FORMAT, AUDIO_DEVICE_CHANNELS, AUDIO.System.device.sampleRate, 0, AUDIO_BUFFER_USAGE_STATIC);
if (audioBuffer == NULL)
{
TRACELOG(LOG_WARNING, "SOUND: Failed to create buffer");
return sound; // early return to avoid dereferencing the audioBuffer null pointer
}
audioBuffer->sizeInFrames = source.stream.buffer->sizeInFrames;
audioBuffer->volume = source.stream.buffer->volume;
audioBuffer->data = source.stream.buffer->data;

sound.frameCount = source.frameCount;
sound.stream.sampleRate = AUDIO.System.device.sampleRate;
sound.stream.sampleSize = 32;
Expand All @@ -953,6 +955,7 @@ Sound LoadSoundAlias(Sound source)
return sound;
}


// Checks if a sound is ready
bool IsSoundReady(Sound sound)
{
Expand Down