From d263478e83bf03a3dad0b711b35dd53343809fae Mon Sep 17 00:00:00 2001 From: Aaron Culliney Date: Sat, 12 Sep 2015 15:04:09 -0700 Subject: [PATCH] Use calloc() for soundcore allocations - Avoids potential for transacting upon uninitialized memory, thank you Valgrind --- src/audio/soundcore-openal.c | 8 ++++---- src/audio/soundcore-opensles.c | 12 ++++++------ src/audio/soundcore.c | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/audio/soundcore-openal.c b/src/audio/soundcore-openal.c index c14430e6..f50fbaff 100644 --- a/src/audio/soundcore-openal.c +++ b/src/audio/soundcore-openal.c @@ -424,7 +424,7 @@ static ALVoice *_openal_createVoice(unsigned long numChannels) { unsigned long maxSamples = openal_audio_backend.systemSettings.monoBufferSizeSamples * numChannels; voice->buffersize = maxSamples * openal_audio_backend.systemSettings.bytesPerSample; - voice->data = malloc(voice->buffersize); + voice->data = calloc(1, voice->buffersize); if (voice->data == NULL) { ERRLOG("OOPS, Error allocating %d bytes", voice->buffersize); break; @@ -497,7 +497,7 @@ static long openal_createSoundBuffer(const AudioContext_s *audio_context, INOUT vnode->voice = voice; HASH_ADD_INT(voices, source, vnode); - if ((*soundbuf_struct = malloc(sizeof(AudioBuffer_s))) == NULL) { + if ((*soundbuf_struct = calloc(1, sizeof(AudioBuffer_s))) == NULL) { ERRLOG("OOPS, Not enough memory"); break; } @@ -566,7 +566,7 @@ static long openal_systemSetup(INOUT AudioContext_s **audio_context) { LOG("WARNING - AL_SOFT_buffer_samples extension not supported... Proceeding anyway..."); } - if ((*audio_context = malloc(sizeof(AudioContext_s))) == NULL) { + if ((*audio_context = calloc(1, sizeof(AudioContext_s))) == NULL) { ERRLOG("OOPS, Not enough memory"); break; } @@ -580,7 +580,7 @@ static long openal_systemSetup(INOUT AudioContext_s **audio_context) { if (result) { if (ctx) { - AudioContext_s *ctxPtr = malloc(sizeof(AudioContext_s)); + AudioContext_s *ctxPtr = calloc(1, sizeof(AudioContext_s)); ctxPtr->_internal = ctx; openal_systemShutdown(&ctxPtr); } diff --git a/src/audio/soundcore-opensles.c b/src/audio/soundcore-opensles.c index 926d96f9..479f5c7b 100644 --- a/src/audio/soundcore-opensles.c +++ b/src/audio/soundcore-opensles.c @@ -84,7 +84,7 @@ static inline bool _underrun_check_and_manage(SLVoice *voice, OUTPARM unsigned l ((readHead >= voice->writeHead) && (readWrapCount == voice->writeWrapCount)) ) { isUnder = true; - LOG("Buffer underrun ..."); + //LOG("Buffer underrun ..."); voice->writeHead = readHead; voice->writeWrapCount = readWrapCount; } @@ -433,7 +433,7 @@ static long opensl_createSoundBuffer(const AudioContext_s *audio_context, INOUT } voice->bufferSize = bufferSize; // Allocate enough space for the temp buffer (including a maximum allowed overflow) - voice->ringBuffer = malloc(voice->bufferSize + ctx->submitSize/*max overflow*/); + voice->ringBuffer = calloc(1, voice->bufferSize + ctx->submitSize/*max overflow*/); if (voice->ringBuffer == NULL) { ERRLOG("OOPS, Error allocating %lu bytes", (unsigned long)voice->bufferSize+ctx->submitSize); break; @@ -444,7 +444,7 @@ static long opensl_createSoundBuffer(const AudioContext_s *audio_context, INOUT voice->ctx = ctx; - if ((*soundbuf_struct = malloc(sizeof(AudioBuffer_s))) == NULL) { + if ((*soundbuf_struct = calloc(1, sizeof(AudioBuffer_s))) == NULL) { ERRLOG("OOPS, Not enough memory"); break; } @@ -563,7 +563,7 @@ static long opensles_systemSetup(INOUT AudioContext_s **audio_context) { } ctx->submitSize = android_stereoBufferSubmitSizeSamples * opensles_audio_backend.systemSettings.bytesPerSample * NUM_CHANNELS; - ctx->mixBuf = malloc(ctx->submitSize); + ctx->mixBuf = calloc(1, ctx->submitSize); if (ctx->mixBuf == NULL) { ERRLOG("OOPS, Error allocating %lu bytes", (unsigned long)ctx->submitSize); break; @@ -608,7 +608,7 @@ static long opensles_systemSetup(INOUT AudioContext_s **audio_context) { } // create soundcore API wrapper - if ((*audio_context = malloc(sizeof(AudioContext_s))) == NULL) { + if ((*audio_context = calloc(1, sizeof(AudioContext_s))) == NULL) { result = -1; ERRLOG("OOPS, Not enough memory"); break; @@ -707,7 +707,7 @@ static long opensles_systemSetup(INOUT AudioContext_s **audio_context) { if (result != SL_RESULT_SUCCESS) { if (ctx) { - AudioContext_s *ctxPtr = malloc(sizeof(AudioContext_s)); + AudioContext_s *ctxPtr = calloc(1, sizeof(AudioContext_s)); ctxPtr->_internal = ctx; opensles_systemShutdown(&ctxPtr); } diff --git a/src/audio/soundcore.c b/src/audio/soundcore.c index 2fb7e9d4..e5164054 100644 --- a/src/audio/soundcore.c +++ b/src/audio/soundcore.c @@ -26,9 +26,9 @@ AudioBackend_s *audio_backend = NULL; //----------------------------------------------------------------------------- long audio_createSoundBuffer(INOUT AudioBuffer_s **audioBuffer) { - *audioBuffer = NULL; if (!audio_isAvailable) { + *audioBuffer = NULL; return -1; }