Prevent memory leak.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2017-07-27 21:04:13 +03:00
parent b0348cbe9f
commit a9367f7ae6

View File

@ -16,6 +16,7 @@
#include <algorithm> #include <algorithm>
#include <sstream> #include <sstream>
#include <cassert> #include <cassert>
#include <QScopedPointer>
#include "intern/drw_textcodec.h" #include "intern/drw_textcodec.h"
#include "intern/dxfreader.h" #include "intern/dxfreader.h"
#include "intern/dxfwriter.h" #include "intern/dxfwriter.h"
@ -2541,18 +2542,18 @@ bool dxfRW::processPolyline() {
bool dxfRW::processVertex(DRW_Polyline *pl) { bool dxfRW::processVertex(DRW_Polyline *pl) {
DRW_DBG("dxfRW::processVertex"); DRW_DBG("dxfRW::processVertex");
int code; int code;
DRW_Vertex *v = new DRW_Vertex(); QScopedPointer<DRW_Vertex> v(new DRW_Vertex());
while (reader->readRec(&code)) { while (reader->readRec(&code)) {
DRW_DBG(code); DRW_DBG("\n"); DRW_DBG(code); DRW_DBG("\n");
switch (code) { switch (code) {
case 0: { case 0: {
pl->appendVertex(v); pl->appendVertex(v.take());
nextentity = reader->getString(); nextentity = reader->getString();
DRW_DBG(nextentity); DRW_DBG("\n"); DRW_DBG(nextentity); DRW_DBG("\n");
if (nextentity == "SEQEND") { if (nextentity == "SEQEND") {
return true; //found SEQEND no more vertex, terminate return true; //found SEQEND no more vertex, terminate
} else if (nextentity == "VERTEX"){ } else if (nextentity == "VERTEX"){
v = new DRW_Vertex(); //another vertex v.reset(new DRW_Vertex()); //another vertex
} }
} }
DRW_FALLTHROUGH DRW_FALLTHROUGH
@ -2561,7 +2562,6 @@ bool dxfRW::processVertex(DRW_Polyline *pl) {
break; break;
} }
} }
delete v;
return true; return true;
} }