Allocate temp storage for delays when loading HRTFs

This commit is contained in:
Chris Robinson
2017-04-07 06:40:42 -07:00
parent 36f7dda1ca
commit b551291840
+11 -8
View File
@@ -317,7 +317,7 @@ static struct Hrtf *LoadHrtf00(const ALubyte *data, size_t datalen, const char *
ALubyte *azCount = NULL;
ALushort *evOffset = NULL;
ALshort *coeffs = NULL;
const ALubyte *delays = NULL;
ALubyte *delays = NULL;
ALuint i, j;
if(datalen < 9)
@@ -416,6 +416,7 @@ static struct Hrtf *LoadHrtf00(const ALubyte *data, size_t datalen, const char *
if(!failed)
{
coeffs = malloc(sizeof(coeffs[0])*irSize*irCount);
delays = malloc(sizeof(delays[0])*irCount);
if(coeffs == NULL)
{
ERR("Out of memory.\n");
@@ -446,11 +447,10 @@ static struct Hrtf *LoadHrtf00(const ALubyte *data, size_t datalen, const char *
}
}
delays = data;
data += irCount;
datalen -= irCount;
for(i = 0;i < irCount;i++)
{
delays[i] = *(data++);
datalen -= 1;
if(delays[i] > maxDelay)
{
ERR("Invalid delays[%d]: %d (%d)\n", i, delays[i], maxDelay);
@@ -466,6 +466,7 @@ static struct Hrtf *LoadHrtf00(const ALubyte *data, size_t datalen, const char *
free(azCount);
free(evOffset);
free(coeffs);
free(delays);
return Hrtf;
}
@@ -479,7 +480,7 @@ static struct Hrtf *LoadHrtf01(const ALubyte *data, size_t datalen, const char *
const ALubyte *azCount = NULL;
ALushort *evOffset = NULL;
ALshort *coeffs = NULL;
const ALubyte *delays = NULL;
ALubyte *delays = NULL;
ALuint i, j;
if(datalen < 6)
@@ -556,6 +557,7 @@ static struct Hrtf *LoadHrtf01(const ALubyte *data, size_t datalen, const char *
}
coeffs = malloc(sizeof(coeffs[0])*irSize*irCount);
delays = malloc(sizeof(delays[0])*irCount);
if(coeffs == NULL)
{
ERR("Out of memory.\n");
@@ -588,11 +590,10 @@ static struct Hrtf *LoadHrtf01(const ALubyte *data, size_t datalen, const char *
}
}
delays = data;
data += irCount;
datalen -= irCount;
for(i = 0;i < irCount;i++)
{
delays[i] = *(data++);
datalen -= 1;
if(delays[i] > maxDelay)
{
ERR("Invalid delays[%d]: %d (%d)\n", i, delays[i], maxDelay);
@@ -607,9 +608,11 @@ static struct Hrtf *LoadHrtf01(const ALubyte *data, size_t datalen, const char *
free(evOffset);
free(coeffs);
free(delays);
return Hrtf;
}
static void AddFileEntry(vector_EnumeratedHrtf *list, const_al_string filename)
{
EnumeratedHrtf entry = { AL_STRING_INIT_STATIC(), NULL };