Fix memory leaks appearing when cvOpenFileStorage throws
This commit is contained in:
parent
183454a723
commit
16ce114e0c
@ -2724,7 +2724,10 @@ cvOpenFileStorage( const char* filename, CvMemStorage* dststorage, int flags, co
|
|||||||
(dot_pos[3] == '\0' || (cv_isdigit(dot_pos[3]) && dot_pos[4] == '\0')) )
|
(dot_pos[3] == '\0' || (cv_isdigit(dot_pos[3]) && dot_pos[4] == '\0')) )
|
||||||
{
|
{
|
||||||
if( append )
|
if( append )
|
||||||
|
{
|
||||||
|
cvReleaseFileStorage( &fs );
|
||||||
CV_Error(CV_StsNotImplemented, "Appending data to compressed file is not implemented" );
|
CV_Error(CV_StsNotImplemented, "Appending data to compressed file is not implemented" );
|
||||||
|
}
|
||||||
isGZ = true;
|
isGZ = true;
|
||||||
compression = dot_pos[3];
|
compression = dot_pos[3];
|
||||||
if( compression )
|
if( compression )
|
||||||
@ -2745,6 +2748,7 @@ cvOpenFileStorage( const char* filename, CvMemStorage* dststorage, int flags, co
|
|||||||
if( !fs->gzfile )
|
if( !fs->gzfile )
|
||||||
goto _exit_;
|
goto _exit_;
|
||||||
#else
|
#else
|
||||||
|
cvReleaseFileStorage( &fs );
|
||||||
CV_Error(CV_StsNotImplemented, "There is no compressed file storage support in this configuration");
|
CV_Error(CV_StsNotImplemented, "There is no compressed file storage support in this configuration");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -2797,7 +2801,10 @@ cvOpenFileStorage( const char* filename, CvMemStorage* dststorage, int flags, co
|
|||||||
if( strcmp( encoding, "UTF-16" ) == 0 ||
|
if( strcmp( encoding, "UTF-16" ) == 0 ||
|
||||||
strcmp( encoding, "utf-16" ) == 0 ||
|
strcmp( encoding, "utf-16" ) == 0 ||
|
||||||
strcmp( encoding, "Utf-16" ) == 0 )
|
strcmp( encoding, "Utf-16" ) == 0 )
|
||||||
|
{
|
||||||
|
cvReleaseFileStorage( &fs );
|
||||||
CV_Error( CV_StsBadArg, "UTF-16 XML encoding is not supported! Use 8-bit encoding\n");
|
CV_Error( CV_StsBadArg, "UTF-16 XML encoding is not supported! Use 8-bit encoding\n");
|
||||||
|
}
|
||||||
|
|
||||||
CV_Assert( strlen(encoding) < 1000 );
|
CV_Assert( strlen(encoding) < 1000 );
|
||||||
char buf[1100];
|
char buf[1100];
|
||||||
@ -2834,7 +2841,10 @@ cvOpenFileStorage( const char* filename, CvMemStorage* dststorage, int flags, co
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if( last_occurence < 0 )
|
if( last_occurence < 0 )
|
||||||
|
{
|
||||||
|
cvReleaseFileStorage( &fs );
|
||||||
CV_Error( CV_StsError, "Could not find </opencv_storage> in the end of file.\n" );
|
CV_Error( CV_StsError, "Could not find </opencv_storage> in the end of file.\n" );
|
||||||
|
}
|
||||||
icvCloseFile( fs );
|
icvCloseFile( fs );
|
||||||
fs->file = fopen( fs->filename, "r+t" );
|
fs->file = fopen( fs->filename, "r+t" );
|
||||||
fseek( fs->file, last_occurence, SEEK_SET );
|
fseek( fs->file, last_occurence, SEEK_SET );
|
||||||
@ -2908,10 +2918,18 @@ cvOpenFileStorage( const char* filename, CvMemStorage* dststorage, int flags, co
|
|||||||
|
|
||||||
//mode = cvGetErrMode();
|
//mode = cvGetErrMode();
|
||||||
//cvSetErrMode( CV_ErrModeSilent );
|
//cvSetErrMode( CV_ErrModeSilent );
|
||||||
if( fs->fmt == CV_STORAGE_FORMAT_XML )
|
try
|
||||||
icvXMLParse( fs );
|
{
|
||||||
else
|
if( fs->fmt == CV_STORAGE_FORMAT_XML )
|
||||||
icvYMLParse( fs );
|
icvXMLParse( fs );
|
||||||
|
else
|
||||||
|
icvYMLParse( fs );
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
cvReleaseFileStorage( &fs );
|
||||||
|
throw;
|
||||||
|
}
|
||||||
//cvSetErrMode( mode );
|
//cvSetErrMode( mode );
|
||||||
|
|
||||||
// release resources that we do not need anymore
|
// release resources that we do not need anymore
|
||||||
|
Loading…
Reference in New Issue
Block a user