mirror of
https://github.com/mauiaaron/apple2.git
synced 2025-01-16 01:31:06 +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;
|
unsigned long maxSamples = openal_audio_backend.systemSettings.monoBufferSizeSamples * numChannels;
|
||||||
voice->buffersize = maxSamples * openal_audio_backend.systemSettings.bytesPerSample;
|
voice->buffersize = maxSamples * openal_audio_backend.systemSettings.bytesPerSample;
|
||||||
|
|
||||||
voice->data = malloc(voice->buffersize);
|
voice->data = calloc(1, voice->buffersize);
|
||||||
if (voice->data == NULL) {
|
if (voice->data == NULL) {
|
||||||
ERRLOG("OOPS, Error allocating %d bytes", voice->buffersize);
|
ERRLOG("OOPS, Error allocating %d bytes", voice->buffersize);
|
||||||
break;
|
break;
|
||||||
@ -497,7 +497,7 @@ static long openal_createSoundBuffer(const AudioContext_s *audio_context, INOUT
|
|||||||
vnode->voice = voice;
|
vnode->voice = voice;
|
||||||
HASH_ADD_INT(voices, source, vnode);
|
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");
|
ERRLOG("OOPS, Not enough memory");
|
||||||
break;
|
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...");
|
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");
|
ERRLOG("OOPS, Not enough memory");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -580,7 +580,7 @@ static long openal_systemSetup(INOUT AudioContext_s **audio_context) {
|
|||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
if (ctx) {
|
if (ctx) {
|
||||||
AudioContext_s *ctxPtr = malloc(sizeof(AudioContext_s));
|
AudioContext_s *ctxPtr = calloc(1, sizeof(AudioContext_s));
|
||||||
ctxPtr->_internal = ctx;
|
ctxPtr->_internal = ctx;
|
||||||
openal_systemShutdown(&ctxPtr);
|
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)) )
|
((readHead >= voice->writeHead) && (readWrapCount == voice->writeWrapCount)) )
|
||||||
{
|
{
|
||||||
isUnder = true;
|
isUnder = true;
|
||||||
LOG("Buffer underrun ...");
|
//LOG("Buffer underrun ...");
|
||||||
voice->writeHead = readHead;
|
voice->writeHead = readHead;
|
||||||
voice->writeWrapCount = readWrapCount;
|
voice->writeWrapCount = readWrapCount;
|
||||||
}
|
}
|
||||||
@ -433,7 +433,7 @@ static long opensl_createSoundBuffer(const AudioContext_s *audio_context, INOUT
|
|||||||
}
|
}
|
||||||
voice->bufferSize = bufferSize;
|
voice->bufferSize = bufferSize;
|
||||||
// Allocate enough space for the temp buffer (including a maximum allowed overflow)
|
// 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) {
|
if (voice->ringBuffer == NULL) {
|
||||||
ERRLOG("OOPS, Error allocating %lu bytes", (unsigned long)voice->bufferSize+ctx->submitSize);
|
ERRLOG("OOPS, Error allocating %lu bytes", (unsigned long)voice->bufferSize+ctx->submitSize);
|
||||||
break;
|
break;
|
||||||
@ -444,7 +444,7 @@ static long opensl_createSoundBuffer(const AudioContext_s *audio_context, INOUT
|
|||||||
|
|
||||||
voice->ctx = ctx;
|
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");
|
ERRLOG("OOPS, Not enough memory");
|
||||||
break;
|
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->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) {
|
if (ctx->mixBuf == NULL) {
|
||||||
ERRLOG("OOPS, Error allocating %lu bytes", (unsigned long)ctx->submitSize);
|
ERRLOG("OOPS, Error allocating %lu bytes", (unsigned long)ctx->submitSize);
|
||||||
break;
|
break;
|
||||||
@ -608,7 +608,7 @@ static long opensles_systemSetup(INOUT AudioContext_s **audio_context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create soundcore API wrapper
|
// create soundcore API wrapper
|
||||||
if ((*audio_context = malloc(sizeof(AudioContext_s))) == NULL) {
|
if ((*audio_context = calloc(1, sizeof(AudioContext_s))) == NULL) {
|
||||||
result = -1;
|
result = -1;
|
||||||
ERRLOG("OOPS, Not enough memory");
|
ERRLOG("OOPS, Not enough memory");
|
||||||
break;
|
break;
|
||||||
@ -707,7 +707,7 @@ static long opensles_systemSetup(INOUT AudioContext_s **audio_context) {
|
|||||||
|
|
||||||
if (result != SL_RESULT_SUCCESS) {
|
if (result != SL_RESULT_SUCCESS) {
|
||||||
if (ctx) {
|
if (ctx) {
|
||||||
AudioContext_s *ctxPtr = malloc(sizeof(AudioContext_s));
|
AudioContext_s *ctxPtr = calloc(1, sizeof(AudioContext_s));
|
||||||
ctxPtr->_internal = ctx;
|
ctxPtr->_internal = ctx;
|
||||||
opensles_systemShutdown(&ctxPtr);
|
opensles_systemShutdown(&ctxPtr);
|
||||||
}
|
}
|
||||||
|
@ -26,9 +26,9 @@ AudioBackend_s *audio_backend = NULL;
|
|||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
long audio_createSoundBuffer(INOUT AudioBuffer_s **audioBuffer) {
|
long audio_createSoundBuffer(INOUT AudioBuffer_s **audioBuffer) {
|
||||||
*audioBuffer = NULL;
|
|
||||||
|
|
||||||
if (!audio_isAvailable) {
|
if (!audio_isAvailable) {
|
||||||
|
*audioBuffer = NULL;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user