From 5fadd6f9abb28e853a6f6c3cdd5601e6759e99f5 Mon Sep 17 00:00:00 2001 From: Anton Sokolchenko Date: Wed, 9 Apr 2014 23:25:54 +0300 Subject: [PATCH 1/2] Fix memory leak 471: If this executed "if (!file.file) ", then 473: dynamically allocated variable "data" is leaked. --- cocos/audio/openal/SimpleAudioEngineOpenAL.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cocos/audio/openal/SimpleAudioEngineOpenAL.cpp b/cocos/audio/openal/SimpleAudioEngineOpenAL.cpp index fafa8f89a8..b4248f2a90 100644 --- a/cocos/audio/openal/SimpleAudioEngineOpenAL.cpp +++ b/cocos/audio/openal/SimpleAudioEngineOpenAL.cpp @@ -462,7 +462,7 @@ void SimpleAudioEngine::preloadEffect(const char* pszFilePath) { ALuint buffer = AL_NONE; ALuint source = AL_NONE; - soundData *data = new soundData; + checkALError("preloadEffect:init"); OpenALFile file; @@ -472,7 +472,7 @@ void SimpleAudioEngine::preloadEffect(const char* pszFilePath) fprintf(stderr, "Cannot read file: '%s'\n", fullPath.data()); return; } - + soundData *data = new soundData; bool success = false; const std::vector &decoders = OpenALDecoder::getDecoders(); for (size_t i = 0, n = decoders.size(); !success && i < n; ++i) From eb568998b241cb15dc4893183cc36ffbf5c4bc82 Mon Sep 17 00:00:00 2001 From: Anton Sokolchenko Date: Thu, 10 Apr 2014 01:00:23 +0300 Subject: [PATCH 2/2] Update SimpleAudioEngineOpenAL.cpp --- cocos/audio/openal/SimpleAudioEngineOpenAL.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cocos/audio/openal/SimpleAudioEngineOpenAL.cpp b/cocos/audio/openal/SimpleAudioEngineOpenAL.cpp index b4248f2a90..31872e5ec7 100644 --- a/cocos/audio/openal/SimpleAudioEngineOpenAL.cpp +++ b/cocos/audio/openal/SimpleAudioEngineOpenAL.cpp @@ -472,7 +472,7 @@ void SimpleAudioEngine::preloadEffect(const char* pszFilePath) fprintf(stderr, "Cannot read file: '%s'\n", fullPath.data()); return; } - soundData *data = new soundData; + bool success = false; const std::vector &decoders = OpenALDecoder::getDecoders(); for (size_t i = 0, n = decoders.size(); !success && i < n; ++i) @@ -489,7 +489,8 @@ void SimpleAudioEngine::preloadEffect(const char* pszFilePath) alSourcei(source, AL_BUFFER, buffer); checkALError("preloadEffect:alSourcei"); - + + soundData *data = new soundData; data->isLooped = false; data->buffer = buffer; data->source = source;