From 96d06929eaf2de6771af991a7851951dc10f91ac Mon Sep 17 00:00:00 2001 From: John Beard <john.j.beard@gmail.com> Date: Fri, 28 Sep 2018 17:59:42 +0100 Subject: [PATCH] QA: Fix ownership of new CPolyline in qa_shape_poly_set_refactor CPolyLine::Chamfer returns a newly allocated object. The current test of this doesn't take ownership, leading to memory leaks. Use a std::unique_ptr to: * Fix the leak, and * Document the expected semantics of the interface in the test Fixes coverity:183869 --- qa/shape_poly_set_refactor/test_chamfer.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/qa/shape_poly_set_refactor/test_chamfer.cpp b/qa/shape_poly_set_refactor/test_chamfer.cpp index 22dc245c4e..7d8a168591 100644 --- a/qa/shape_poly_set_refactor/test_chamfer.cpp +++ b/qa/shape_poly_set_refactor/test_chamfer.cpp @@ -99,23 +99,24 @@ void TestLineChainEqualCPolyLine(SHAPE_LINE_CHAIN& lineChain, CPolyLine& polyLin BOOST_AUTO_TEST_CASE( Chamfer ) { SHAPE_POLY_SET::POLYGON actual; - CPolyLine expected; // Test different distances, up to the half of the minimum segment longitude - for (int distance = 0; distance < 5; distance++) { + for( int distance = 0; distance < 5; distance++ ) + { // Chamfered polygon to be tested. actual = common.holeyPolySet.ChamferPolygon( distance, 0 ); // Chamfered polygon assumed to be right. - expected = *legacyPolyLine.Chamfer( distance ); + // CPolyline::Chamfer returns new CPolyline - take ownership + std::unique_ptr<CPolyLine> expected( legacyPolyLine.Chamfer( distance ) ); // Double check that there are no repeated corners in the legacy shape. - expected.RemoveNullSegments(); + expected->RemoveNullSegments(); // Test equality - for (size_t contourIdx = 0; contourIdx < actual.size(); contourIdx++) + for( size_t contourIdx = 0; contourIdx < actual.size(); contourIdx++ ) { - TestLineChainEqualCPolyLine(actual[contourIdx], expected, contourIdx); + TestLineChainEqualCPolyLine(actual[contourIdx], *expected, contourIdx); } } }