aboutsummaryrefslogtreecommitdiff
path: root/engines/sword2/music.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'engines/sword2/music.cpp')
-rw-r--r--engines/sword2/music.cpp13
1 files changed, 10 insertions, 3 deletions
diff --git a/engines/sword2/music.cpp b/engines/sword2/music.cpp
index c052aa6b46..89073fef8e 100644
--- a/engines/sword2/music.cpp
+++ b/engines/sword2/music.cpp
@@ -496,9 +496,16 @@ int Sound::readBuffer(int16 *buffer, const int numSamples) {
memset(buffer, 0, 2 * numSamples);
if (!_mixBuffer || numSamples > _mixBufferLen) {
- if (_mixBuffer)
- _mixBuffer = (int16 *)realloc(_mixBuffer, 2 * numSamples);
- else
+ if (_mixBuffer) {
+ int16 *newBuffer = (int16 *)realloc(_mixBuffer, 2 * numSamples);
+ if (newBuffer) {
+ _mixBuffer = newBuffer;
+ } else {
+ // We can't use the old buffer any more. It's too small.
+ free(_mixBuffer);
+ _mixBuffer = 0;
+ }
+ } else
_mixBuffer = (int16 *)malloc(2 * numSamples);
_mixBufferLen = numSamples;