summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorLukas <[email protected]>2023-10-23 18:16:28 +0200
committerGitHub <[email protected]>2023-10-23 18:16:28 +0200
commitdaf227a185808d1e37e4269cf4a5be6b690226f6 (patch)
tree2d19fd3cd1e0bab1ca8d15d4d886908b745fe756
parent4ed776368a488b242781d77753f4b11396f97ce7 (diff)
downloadraylib-daf227a185808d1e37e4269cf4a5be6b690226f6.tar.gz
raylib-daf227a185808d1e37e4269cf4a5be6b690226f6.zip
Fixes a memory leak as a result of creating an AudioBuffer* with the old source.frameCount. This internally allocates memory to the structs data pointer which is then later overridden by the correct sound data of the source sound. (#3458)
Additionally added a volume assignment from old to new as currently there is no way to get the volume of a sound and the AudioBuffer struct is not reachable from user code due to opaque definition.
-rw-r--r--src/raudio.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/raudio.c b/src/raudio.c
index 6a109676..dcc9f706 100644
--- a/src/raudio.c
+++ b/src/raudio.c
@@ -928,7 +928,6 @@ 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)
{
@@ -936,13 +935,16 @@ Sound LoadSoundAlias(Sound source)
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;
@@ -953,6 +955,7 @@ Sound LoadSoundAlias(Sound source)
return sound;
}
+
// Checks if a sound is ready
bool IsSoundReady(Sound sound)
{