From 07a17af70ac490e73e4f291fce774739c167c89a Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 14 Nov 2012 17:12:42 +0100 Subject: [PATCH] Fix some memory leaks --- src/Mod/Sketcher/Gui/SoDatumLabel.cpp | 6 +++--- src/Mod/Sketcher/Gui/ViewProviderSketch.cpp | 6 +++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Mod/Sketcher/Gui/SoDatumLabel.cpp b/src/Mod/Sketcher/Gui/SoDatumLabel.cpp index 45de2331c..f2fc0005c 100644 --- a/src/Mod/Sketcher/Gui/SoDatumLabel.cpp +++ b/src/Mod/Sketcher/Gui/SoDatumLabel.cpp @@ -835,10 +835,10 @@ void SoDatumLabel::GLRender(SoGLRenderAction * action) SbVec3f z = vv.zVector(); const SbViewportRegion & vpr = SoViewportRegionElement::get(state); - SoGetMatrixAction * getmatrixaction = new SoGetMatrixAction(vpr); - getmatrixaction->apply(action); + SoGetMatrixAction getmatrixaction(vpr); + getmatrixaction.apply(action); - SbMatrix transform = getmatrixaction->getMatrix(); + SbMatrix transform = getmatrixaction.getMatrix(); transform.multVecMatrix(surfNorm, surfNorm); bool flip = surfNorm.dot(z) > FLT_EPSILON; diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp index 258f4ea51..29118960b 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp @@ -2631,6 +2631,9 @@ void ViewProviderSketch::rebuildConstraintsVisual(void) // every constrained visual node gets its own material for preselection and selection SoMaterial *Material = new SoMaterial; + // Not all kind of constraints need a material. So, increment its counter here and decrement + // it later to avoid a memory leak. + Material->ref(); Material->diffuseColor = ConstrDimColor; // distinguish different constraint types to build up @@ -2718,9 +2721,10 @@ void ViewProviderSketch::rebuildConstraintsVisual(void) break; default: edit->vConstrType.push_back(None); - } + } edit->constrGroup->addChild(sep); + Material->unref(); } }