mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-25 00:58:06 -05:00
- plugged memory leak in QgsShapeFileProvider::getFirstFeature() whereby the
OGRFeature wasn't getting destroyed - made getFirstFeature() a little more robust with regards to handling memory related errors - implementation files should include their own headers first, so moved its #include accordingly to top; the meant creating class forward declarations in header file. git-svn-id: http://svn.osgeo.org/qgis/trunk@1105 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
parent
d57835a2b7
commit
4f120dc186
@ -1,15 +1,22 @@
|
||||
/* QGIS data provider for ESRI Shapefile format */
|
||||
/* $Id$ */
|
||||
|
||||
#include "qgsshapefileprovider.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <cfloat>
|
||||
|
||||
#include <ogrsf_frmts.h>
|
||||
#include <ogr_geometry.h>
|
||||
#include <cpl_error.h>
|
||||
|
||||
#include <qguardedptr.h>
|
||||
|
||||
#include "../../src/qgsdataprovider.h"
|
||||
#include "../../src/qgsfeature.h"
|
||||
#include "../../src/qgsfield.h"
|
||||
#include "../../src/qgsrect.h"
|
||||
#include <ogrsf_frmts.h>
|
||||
#include <ogr_geometry.h>
|
||||
#include <cpl_error.h>
|
||||
#include "qgsshapefileprovider.h"
|
||||
#include <cfloat>
|
||||
|
||||
|
||||
QgsShapeFileProvider::QgsShapeFileProvider(QString uri):dataSourceUri(uri), minmaxcachedirty(true)
|
||||
{
|
||||
@ -100,32 +107,61 @@ QgsShapeFileProvider::~QgsShapeFileProvider()
|
||||
* Get the first feature resutling from a select operation
|
||||
* @return QgsFeature
|
||||
*/
|
||||
QgsFeature *QgsShapeFileProvider::getFirstFeature(bool fetchAttributes)
|
||||
QgsFeature * QgsShapeFileProvider::getFirstFeature(bool fetchAttributes)
|
||||
{
|
||||
QgsFeature *f = 0;
|
||||
if(valid){
|
||||
|
||||
if(valid)
|
||||
{
|
||||
#ifdef QGISDEBUG
|
||||
std::cerr << "getting first feature\n";
|
||||
#endif
|
||||
ogrLayer->ResetReading();
|
||||
OGRFeature *feat = ogrLayer->GetNextFeature();
|
||||
if(feat){
|
||||
|
||||
// use QGuardedPtr to insure feat is destroyed no matter how we exit this function
|
||||
QGuardedPtr<OGRFeature> feat = ogrLayer->GetNextFeature();
|
||||
|
||||
Q_ASSERT( ! feat.isNull() );
|
||||
|
||||
if(feat)
|
||||
{
|
||||
#ifdef QGISDEBUG
|
||||
std::cerr << "First feature is not null\n";
|
||||
#endif
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef QGISDEBUG
|
||||
std::cerr << "First feature is null\n";
|
||||
|
||||
#endif
|
||||
return 0x0; // so return a null feature indicating that we got a null feature
|
||||
}
|
||||
|
||||
f = new QgsFeature(feat->GetFID());
|
||||
|
||||
Q_CHECK_PTR( f );
|
||||
|
||||
if ( ! f ) // return null if we can't get a new QgsFeature
|
||||
{
|
||||
return 0x0;
|
||||
}
|
||||
|
||||
f->setGeometry(getGeometryPointer(feat));
|
||||
if(fetchAttributes){
|
||||
|
||||
if(fetchAttributes)
|
||||
{
|
||||
getFeatureAttributes(feat, f);
|
||||
}
|
||||
}
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
} // QgsShapeFileProvider::getFirstFeature()
|
||||
|
||||
|
||||
|
||||
|
||||
bool QgsShapeFileProvider::getNextFeature(QgsFeature &f, bool fetchAttributes)
|
||||
{
|
||||
bool returnValue;
|
||||
|
@ -17,10 +17,14 @@ email : sherman at mrcc.com
|
||||
/* $Id$ */
|
||||
|
||||
#include "../../src/qgsdataprovider.h"
|
||||
|
||||
class QgsFeature;
|
||||
class QgsField;
|
||||
class OGRDataSource;
|
||||
class OGRLayer;
|
||||
class OGRFeature;
|
||||
class OGREnvelope;
|
||||
|
||||
/**
|
||||
\class QgsShapeFileProvider
|
||||
\brief Data provider for ESRI shapefiles
|
||||
|
Loading…
x
Reference in New Issue
Block a user