Merge pull request #1173 from kyzentun/no_alloca_in_sound

Alloca problems
This commit is contained in:
Kyzentun
2016-06-24 16:50:45 -06:00
committed by GitHub
4 changed files with 22 additions and 11 deletions
-1
View File
@@ -668,7 +668,6 @@ int RageSoundReader_Resample_Good::Read( float *pBuf, int iFrames )
{
int iFramesNeeded = m_apResamplers[0]->NumInputsForOutputSamples(iFrames);
float *pTmpBuf = (float *) alloca( iFramesNeeded * sizeof(float) * iChannels );
ASSERT( pTmpBuf != NULL );
int iFramesIn = m_pSource->Read( pTmpBuf, iFramesNeeded );
if( iFramesIn < 0 )
return iFramesIn;
+3 -1
View File
@@ -89,10 +89,11 @@ int RageSoundReader_SpeedChange::FillData( int iMaxFrames )
if( iBytesToRead <= 0 )
return m_iDataBufferAvailFrames;
float *pTempBuffer = (float *) alloca( iBytesToRead );
float* pTempBuffer= new float[iBytesToRead/sizeof(float)];
int iGotFrames = m_pSource->Read( pTempBuffer, iFramesToRead );
if( iGotFrames < 0 )
{
delete[] pTempBuffer;
if( iGotFrames == END_OF_FILE && m_iDataBufferAvailFrames )
return m_iDataBufferAvailFrames;
return iGotFrames;
@@ -114,6 +115,7 @@ int RageSoundReader_SpeedChange::FillData( int iMaxFrames )
++pOut;
}
}
delete[] pTempBuffer;
m_iDataBufferAvailFrames += iGotFrames;
}
-1
View File
@@ -289,7 +289,6 @@ public:
int iMaxSize = min( (int) m_WavData.m_iBlockAlign - 7 * m_WavData.m_iChannels, (m_WavData.m_iDataChunkSize+m_WavData.m_iDataChunkPos) - m_File.Tell() );
char *pBuf = (char *) alloca( iMaxSize );
ASSERT( pBuf != NULL );
int iBlockSize = m_File.Read( pBuf, iMaxSize );
if( iBlockSize == 0 )
+19 -8
View File
@@ -50,7 +50,10 @@ void PNG_Error( png_struct *png, const char *error )
strncpy( info->err, error, 1024 );
info->err[1023] = 0;
LOG->Trace( "loading \"%s\": err: %s", info->fn, info->err );
longjmp( png_jmpbuf(png), 1 );
// This exception is just thrown to go to the catch block for cleanup. The
// message has already been printed, so the exception value can be ignored.
// -Kyz
throw int(1);
}
void PNG_Warning( png_struct *png, const char *warning )
@@ -87,12 +90,10 @@ static RageSurface *RageSurface_Load_PNG( RageFile *f, const char *fn, char erro
RageSurface *volatile img = NULL;
CHECKPOINT_M("Potential issue with png jump about to be analyzed.");
if( setjmp(png_jmpbuf(png) ))
png_byte** row_pointers= NULL;
try
{
png_destroy_read_struct( &png, &info_ptr, NULL );
delete img;
return NULL;
}
png_set_read_fn( png, f, RageFile_png_read );
@@ -227,8 +228,7 @@ static RageSurface *RageSurface_Load_PNG( RageFile *f, const char *fn, char erro
}
ASSERT( img != NULL );
/* alloca to prevent memleaks if libpng longjmps us */
png_byte **row_pointers = (png_byte **) alloca( sizeof(png_byte*) * height );
row_pointers = new png_byte*[height];
CHECKPOINT_M( ssprintf("%p",row_pointers) );
for( unsigned y = 0; y < height; ++y )
@@ -241,6 +241,17 @@ static RageSurface *RageSurface_Load_PNG( RageFile *f, const char *fn, char erro
png_read_end( png, info_ptr );
png_destroy_read_struct( &png, &info_ptr, NULL );
}
catch(int e)
{
png_destroy_read_struct(&png, &info_ptr, NULL);
delete img;
if(row_pointers != NULL)
{
delete[] row_pointers;
}
return NULL;
}
return img;
}