fix double free on PICO model parsing error

This commit is contained in:
Garux 2021-03-13 14:54:59 +03:00
parent 4f5f5649dc
commit a5fb9388c2

View File

@ -140,18 +140,14 @@ void PicoSetPrintFunc( void ( *func )( int, const char* ) ){
picoModel_t *PicoModuleLoadModel( const picoModule_t* pm, const char* fileName, picoByte_t* buffer, int bufSize, int frameNum ){
picoModel_t *PicoModuleLoadModel( const picoModule_t* pm, const char* fileName, const picoByte_t* buffer, int bufSize, int frameNum ){
char *modelFileName, *remapFileName;
/* see whether this module can load the model file or not */
if ( pm->canload( fileName, buffer, bufSize ) == PICO_PMV_OK ) {
/* use loader provided by module to read the model data */
picoModel_t* model = pm->load( fileName, frameNum, buffer, bufSize );
if ( model == NULL ) {
_pico_free_file( buffer );
return NULL;
}
if ( model != NULL ) {
/* assign pointer to file format module */
model->module = pm;
@ -174,9 +170,8 @@ picoModel_t *PicoModuleLoadModel( const picoModule_t* pm, const char* fileName,
_pico_free( remapFileName );
}
}
_pico_deduce_shadernames( model );
}
return model;
}
@ -239,9 +234,7 @@ picoModel_t *PicoLoadModel( const char *fileName, int frameNum ){
}
/* free memory used by file buffer */
if ( buffer ) {
_pico_free_file( buffer );
}
/* return */
return model;
@ -273,9 +266,7 @@ picoModel_t *PicoModuleLoadModelStream( const picoModule_t* module, void* inputS
model = PicoModuleLoadModel( module, fileName, buffer, bufSize, frameNum );
if ( model != 0 ) {
_pico_free( buffer );
}
/* return */
return model;