From d4fce2790996c344ded02b8d71e3c24bc36a0e7f Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Mon, 7 Sep 2020 17:40:39 +0900 Subject: [PATCH] sw_engine: fix memory leak. free resources properly at exceptional case. --- src/lib/sw_engine/tvgSwShape.cpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/lib/sw_engine/tvgSwShape.cpp b/src/lib/sw_engine/tvgSwShape.cpp index b738f89a..49bcd12b 100644 --- a/src/lib/sw_engine/tvgSwShape.cpp +++ b/src/lib/sw_engine/tvgSwShape.cpp @@ -618,7 +618,9 @@ void shapeResetStroke(SwShape* shape, const Shape* sdata, const Matrix* transfor bool shapeGenStrokeRle(SwShape* shape, const Shape* sdata, const Matrix* transform, const SwSize& clip) { SwOutline* shapeOutline = nullptr; + SwOutline* strokeOutline = nullptr; bool freeOutline = false; + bool ret = true; //Dash Style Stroke if (sdata->strokeDash(nullptr) > 0) { @@ -633,22 +635,32 @@ bool shapeGenStrokeRle(SwShape* shape, const Shape* sdata, const Matrix* transfo shapeOutline = shape->outline; } - if (!strokeParseOutline(shape->stroke, *shapeOutline)) return false; + if (!strokeParseOutline(shape->stroke, *shapeOutline)) { + ret = false; + goto fail; + } - auto strokeOutline = strokeExportOutline(shape->stroke); - if (!strokeOutline) return false; + strokeOutline = strokeExportOutline(shape->stroke); + if (!strokeOutline) { + ret = false; + goto fail; + } SwBBox bbox; _updateBBox(strokeOutline, bbox); - if (!_checkValid(strokeOutline, bbox, clip)) return false; + if (!_checkValid(strokeOutline, bbox, clip)) { + ret = false; + goto fail; + } shape->strokeRle = rleRender(strokeOutline, bbox, clip, true); +fail: if (freeOutline) _delOutline(shapeOutline); _delOutline(strokeOutline); - return true; + return ret; }