Skip to content

Commit

Permalink
Fix some memory management issues
Browse files Browse the repository at this point in the history
aka reduce noise in valgrind memory analyzer
  • Loading branch information
m-kuhn committed Jun 15, 2013
1 parent d256fd8 commit 1aa8a17
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 29 deletions.
5 changes: 3 additions & 2 deletions python/core/qgsfield.sip
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,14 @@ public:
void extend( const QgsFields& other );


QgsField& operator[](int i);
QgsField& operator[](int i) /Factory/;
%MethodCode
int idx = (int)sipConvertFromSequenceIndex(a0, sipCpp->count());
int idx = sipConvertFromSequenceIndex(a0, sipCpp->count());
if (idx < 0)
sipIsErr = 1;
else
sipRes = new QgsField(sipCpp->operator[](idx));

%End

/* SIP_PYOBJECT __getitem__(int key);
Expand Down
65 changes: 38 additions & 27 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -745,44 +745,46 @@ QgisApp::~QgisApp()
#ifdef HAVE_TOUCH
delete mMapTools.mTouch;
#endif
delete mMapTools.mIdentify;
delete mMapTools.mAddFeature;
delete mMapTools.mAddPart;
delete mMapTools.mAddRing;
delete mMapTools.mAnnotation;
delete mMapTools.mChangeLabelProperties;
delete mMapTools.mDeletePart;
delete mMapTools.mDeleteRing;
delete mMapTools.mFeatureAction;
delete mMapTools.mMeasureDist;
delete mMapTools.mMeasureArea;
delete mMapTools.mMeasureAngle;
delete mMapTools.mTextAnnotation;
delete mMapTools.mFormAnnotation;
delete mMapTools.mHtmlAnnotation;
delete mMapTools.mSvgAnnotation;
delete mMapTools.mAnnotation;
delete mMapTools.mAddFeature;
delete mMapTools.mIdentify;
delete mMapTools.mMeasureAngle;
delete mMapTools.mMeasureArea;
delete mMapTools.mMeasureDist;
delete mMapTools.mMoveFeature;
delete mMapTools.mMoveLabel;
delete mMapTools.mNodeTool;
delete mMapTools.mOffsetCurve;
delete mMapTools.mPinLabels;
delete mMapTools.mReshapeFeatures;
delete mMapTools.mSplitFeatures;
delete mMapTools.mRotateFeature;
delete mMapTools.mRotateLabel;
delete mMapTools.mRotatePointSymbolsTool;
delete mMapTools.mSelect;
delete mMapTools.mSelectRectangle;
delete mMapTools.mSelectPolygon;
delete mMapTools.mSelectFreehand;
delete mMapTools.mSelectPolygon;
delete mMapTools.mSelectRadius;
delete mMapTools.mAddRing;
delete mMapTools.mSimplifyFeature;
delete mMapTools.mDeleteRing;
delete mMapTools.mDeletePart;
delete mMapTools.mAddPart;
delete mMapTools.mNodeTool;
delete mMapTools.mRotatePointSymbolsTool;
delete mMapTools.mPinLabels;
delete mMapTools.mSelectRectangle;
delete mMapTools.mShowHideLabels;
delete mMapTools.mMoveLabel;
delete mMapTools.mRotateFeature;
delete mMapTools.mRotateLabel;
delete mMapTools.mChangeLabelProperties;
delete mMapTools.mOffsetCurve;
delete mMapTools.mSimplifyFeature;
delete mMapTools.mSplitFeatures;
delete mMapTools.mSvgAnnotation;
delete mMapTools.mTextAnnotation;

delete mPythonUtils;
delete mpMaptip;

delete mpGpsWidget;

delete mOverviewMapCursor;

deletePrintComposers();
removeAnnotationItems();

Expand All @@ -791,6 +793,11 @@ QgisApp::~QgisApp()

// delete map layer registry and provider registry
QgsApplication::exitQgis();

delete QgsProject::instance();

mPythonUtils->exitPython();
delete mPythonUtils;
}

void QgisApp::dragEnterEvent( QDragEnterEvent *event )
Expand Down Expand Up @@ -1330,7 +1337,7 @@ void QgisApp::createMenus()
// Help menu
// add What's this button to it
QAction* before = mActionHelpAPI;
mHelpMenu->insertAction( before, QWhatsThis::createAction() );
mHelpMenu->insertAction( before, QWhatsThis::createAction( this ) );
}

void QgisApp::createToolBars()
Expand Down Expand Up @@ -1457,7 +1464,7 @@ void QgisApp::createToolBars()

// Help Toolbar

mHelpToolBar->addAction( QWhatsThis::createAction() );
mHelpToolBar->addAction( QWhatsThis::createAction( this ) );

}

Expand Down Expand Up @@ -2173,6 +2180,10 @@ bool QgisApp::createDB()
return false;
}
}
else
{
sqlite3_free( errmsg );
}

if ( sqlite3_exec( db, "DROP VIEW vw_srs", 0, 0, &errmsg ) != SQLITE_OK )
{
Expand Down
2 changes: 2 additions & 0 deletions src/core/qgscoordinatetransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ void QgsCoordinateTransform::initialise()
}

// init the projections (destination and source)
pj_free( mDestinationProjection );
mDestinationProjection = pj_init_plus( mDestCRS.toProj4().toUtf8() );
pj_free( mSourceProjection );
mSourceProjection = pj_init_plus( mSourceCRS.toProj4().toUtf8() );

#ifdef COORDINATE_TRANSFORM_VERBOSE
Expand Down
2 changes: 2 additions & 0 deletions src/core/qgsvectorfilewriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,10 @@ QgsVectorFileWriter::QgsVectorFileWriter(
.arg( attrField.name() )
.arg( QString::fromUtf8( CPLGetLastErrorMsg() ) );
mError = ErrAttributeCreationFailed;
OGR_Fld_Destroy( fld );
return;
}
OGR_Fld_Destroy( fld );

int ogrIdx = OGR_FD_GetFieldIndex( defn, mCodec->fromUnicode( attrField.name() ) );
if ( ogrIdx < 0 )
Expand Down
2 changes: 2 additions & 0 deletions src/core/qgsvectorlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ QgsVectorLayer::~QgsVectorLayer()

delete mActions;

delete mRendererV2;

//delete remaining overlays

QList<QgsVectorOverlay*>::iterator overlayIt = mOverlays.begin();
Expand Down

0 comments on commit 1aa8a17

Please sign in to comment.