Skip to content

Commit bc89bdb

Browse files
committed
Fix coverity issues:
- possible use after free - uninitialized member
1 parent 17793c3 commit bc89bdb

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

src/plugins/geometry_checker/utils/qgsfeaturepool.cpp

+16-11
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,24 @@ bool QgsFeaturePool::get( QgsFeatureId id , QgsFeature& feature )
5252
{
5353
QMutexLocker lock( &mLayerMutex );
5454
QgsFeature* pfeature = mFeatureCache.object( id );
55-
if ( !pfeature )
55+
if ( pfeature )
5656
{
57-
// Get new feature
58-
pfeature = new QgsFeature();
59-
// TODO: avoid always querying all attributes (attribute values are needed when merging by attribute)
60-
if ( !mLayer->getFeatures( QgsFeatureRequest( id ) ).nextFeature( *pfeature ) )
61-
{
62-
delete pfeature;
63-
return false;
64-
}
65-
mFeatureCache.insert( id, pfeature );
57+
//feature was cached
58+
feature = *pfeature;
6659
}
67-
feature = *pfeature;
60+
61+
// Feature not in cache, retrieve from layer
62+
pfeature = new QgsFeature();
63+
// TODO: avoid always querying all attributes (attribute values are needed when merging by attribute)
64+
if ( !mLayer->getFeatures( QgsFeatureRequest( id ) ).nextFeature( *pfeature ) )
65+
{
66+
delete pfeature;
67+
return false;
68+
}
69+
//make a copy of pfeature into feature parameter
70+
feature = QgsFeature( *pfeature );
71+
//ownership of pfeature is transferred to cache
72+
mFeatureCache.insert( id, pfeature );
6873
return true;
6974
}
7075

src/providers/virtual/qgsvirtuallayersqlitemodule.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ struct VTable
105105
, mSlotToFunction( invalidateTable, this )
106106
, mName( layer->name() )
107107
, mPkColumn( -1 )
108+
, mCrs( -1 )
108109
, mValid( true )
109110
{
110111
if ( mLayer )
@@ -123,6 +124,7 @@ struct VTable
123124
, mName( name )
124125
, mEncoding( encoding )
125126
, mPkColumn( -1 )
127+
, mCrs( -1 )
126128
, mValid( true )
127129
{
128130
mProvider = static_cast<QgsVectorDataProvider*>( QgsProviderRegistry::instance()->provider( provider, source ) );

0 commit comments

Comments
 (0)