Skip to content

Commit

Permalink
Fix memory leak in MsSql provider (identified by Coverity)
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Feb 4, 2015
1 parent 9e9a289 commit b187825
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/providers/mssql/qgsmssqlgeometryparser.cpp
Expand Up @@ -164,7 +164,7 @@ void QgsMssqlGeometryParser::CopyBytes( void* src, int len )
QgsDebugMsg( "CopyBytes wkb buffer realloc" );
unsigned char* pszWkbTmp = new unsigned char[nWkbLen + len + 100];
memcpy( pszWkbTmp, pszWkb, nWkbLen );
delete pszWkb;
delete[] pszWkb;
pszWkb = pszWkbTmp;
nWkbMaxLen = nWkbLen + len + 100;
}
Expand Down Expand Up @@ -499,7 +499,7 @@ unsigned char* QgsMssqlGeometryParser::ParseSqlGeometry( unsigned char* pszInput

if ( nLen < 6 + nPointSize )
{
free( pszWkb );
delete [] pszWkb;
QgsDebugMsg( "ParseSqlGeometry not enough data" );
DumpMemoryToLog( "Not enough data", pszInput, nLen );
return NULL;
Expand All @@ -515,7 +515,7 @@ unsigned char* QgsMssqlGeometryParser::ParseSqlGeometry( unsigned char* pszInput

if ( nLen < 6 + 2 * nPointSize )
{
free( pszWkb );
delete [] pszWkb;
QgsDebugMsg( "ParseSqlGeometry not enough data" );
DumpMemoryToLog( "Not enough data", pszInput, nLen );
return NULL;
Expand Down Expand Up @@ -544,7 +544,7 @@ unsigned char* QgsMssqlGeometryParser::ParseSqlGeometry( unsigned char* pszInput

if ( nNumPoints <= 0 )
{
free( pszWkb );
delete [] pszWkb;
return NULL;
}

Expand All @@ -556,7 +556,7 @@ unsigned char* QgsMssqlGeometryParser::ParseSqlGeometry( unsigned char* pszInput

if ( nLen < nFigurePos )
{
free( pszWkb );
delete [] pszWkb;
QgsDebugMsg( "ParseSqlGeometry not enough data" );
DumpMemoryToLog( "Not enough data", pszInput, nLen );
return NULL;
Expand All @@ -566,7 +566,7 @@ unsigned char* QgsMssqlGeometryParser::ParseSqlGeometry( unsigned char* pszInput

if ( nNumFigures <= 0 )
{
free( pszWkb );
delete [] pszWkb;
return NULL;
}

Expand All @@ -575,7 +575,7 @@ unsigned char* QgsMssqlGeometryParser::ParseSqlGeometry( unsigned char* pszInput

if ( nLen < nShapePos )
{
free( pszWkb );
delete [] pszWkb;
QgsDebugMsg( "ParseSqlGeometry not enough data" );
DumpMemoryToLog( "Not enough data", pszInput, nLen );
return NULL;
Expand All @@ -585,22 +585,22 @@ unsigned char* QgsMssqlGeometryParser::ParseSqlGeometry( unsigned char* pszInput

if ( nLen < nShapePos + 9 * nNumShapes )
{
free( pszWkb );
delete [] pszWkb;
QgsDebugMsg( "ParseSqlGeometry not enough data" );
DumpMemoryToLog( "Not enough data", pszInput, nLen );
return NULL;
}

if ( nNumShapes <= 0 )
{
free( pszWkb );
delete [] pszWkb;
return NULL;
}

// pick up the root shape
if ( ParentOffset( 0 ) != 0xFFFFFFFF )
{
free( pszWkb );
delete [] pszWkb;
QgsDebugMsg( "ParseSqlGeometry corrupt data" );
DumpMemoryToLog( "Not enough data", pszInput, nLen );
return NULL;
Expand Down Expand Up @@ -631,7 +631,7 @@ unsigned char* QgsMssqlGeometryParser::ParseSqlGeometry( unsigned char* pszInput
//ReadGeometryCollection(0);
//break;
default:
free( pszWkb );
delete [] pszWkb;
QgsDebugMsg( "ParseSqlGeometry unsupported geometry type" );
DumpMemoryToLog( "Unsupported geometry type", pszInput, nLen );
return NULL;
Expand Down

0 comments on commit b187825

Please sign in to comment.