Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[Spatialite] Use correct free function for sqlite3_bind_blob of geome…
…tries

Currently sqlite3_bind_blob() uses free() as the free function of WKB
blobs returned by convertFromGeosWKB(). But those are allocated with
new[] and should consequently be freed with delete[].

Spotted by Valgrind:
==4014== Mismatched free() / delete / delete []
==4014==    at 0x4C287BE: free (vg_replace_malloc.c:446)
==4014==    by 0xE42E481: sqlite3VdbeMemReleaseExternal (sqlite3.c:57237)
==4014==    by 0xE42E4E3: sqlite3VdbeMemRelease (sqlite3.c:57252)
==4014==    by 0xE42EC3E: releaseMemArray (sqlite3.c:59208)
==4014==    by 0xE42ED1E: sqlite3VdbeDeleteObject (sqlite3.c:60561)
==4014==    by 0xE46A6DB: sqlite3VdbeFinalize (sqlite3.c:60528)
==4014==    by 0xE46A916: sqlite3_finalize (sqlite3.c:61431)
==4014==    by 0x7FB23958: QgsSpatiaLiteProvider::addFeatures(QList<QgsFeature>&) (qgsspatialiteprovider.cpp:3752)
==4014==  Address 0x8e2a8b30 is 0 bytes inside a block of size 94 alloc'd
==4014==    at 0x4C29520: operator new[](unsigned long) (vg_replace_malloc.c:363)
==4014==    by 0x7FB1B964: QgsSpatiaLiteProvider::convertFromGeosWKB(unsigned char const*, int, unsigned char**, int*, int) (qgsspatialiteprovider.cpp:1341)
==4014==    by 0x7FB234B5: QgsSpatiaLiteProvider::addFeatures(QList<QgsFeature>&) (qgsspatialiteprovider.cpp:3676)

(cherry picked from commit 2e04162)
  • Loading branch information
rouault authored and jef-n committed Mar 23, 2016
1 parent 0147765 commit d364770
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/providers/spatialite/qgsspatialiteprovider.cpp
Expand Up @@ -3532,6 +3532,11 @@ QString QgsSpatiaLiteProvider::geomParam() const
return geometry;
}

static void deleteWkbBlob( void* wkbBlob )
{
delete[]( char* )wkbBlob;
}

bool QgsSpatiaLiteProvider::addFeatures( QgsFeatureList & flist )
{
sqlite3_stmt *stmt = NULL;
Expand Down Expand Up @@ -3615,7 +3620,7 @@ bool QgsSpatiaLiteProvider::addFeatures( QgsFeatureList & flist )
if ( !wkb )
sqlite3_bind_null( stmt, ++ia );
else
sqlite3_bind_blob( stmt, ++ia, wkb, wkb_size, free );
sqlite3_bind_blob( stmt, ++ia, wkb, wkb_size, deleteWkbBlob );
}
}

Expand Down Expand Up @@ -4005,7 +4010,7 @@ bool QgsSpatiaLiteProvider::changeGeometryValues( QgsGeometryMap & geometry_map
if ( !wkb )
sqlite3_bind_null( stmt, 1 );
else
sqlite3_bind_blob( stmt, 1, wkb, wkb_size, free );
sqlite3_bind_blob( stmt, 1, wkb, wkb_size, deleteWkbBlob );
sqlite3_bind_int64( stmt, 2, FID_TO_NUMBER( iter.key() ) );

// performing actual row update
Expand Down

0 comments on commit d364770

Please sign in to comment.