mirror of
https://github.com/mauiaaron/apple2.git
synced 2024-12-28 12:33:04 +00:00
Use calloc() for soundcore allocations
- Avoids potential for transacting upon uninitialized memory, thank you Valgrind
This commit is contained in:
parent
db46b281cc
commit
d263478e83
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user