mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 13:43:43 +00:00
common paint: fix a memory leak.
delete dangling object properly in the corner case. Unfortunately, this brings to correct the capi test cases. we assume the paints is deleted whenever its result is successful or not. @Issue: https://github.com/Samsung/thorvg/issues/995
This commit is contained in:
parent
775a0bcb1d
commit
74413a989f
2 changed files with 15 additions and 7 deletions
|
@ -353,7 +353,9 @@ Paint* Paint::duplicate() const noexcept
|
|||
|
||||
Result Paint::composite(std::unique_ptr<Paint> target, CompositeMethod method) noexcept
|
||||
{
|
||||
if (pImpl->composite(target.release(), method)) return Result::Success;
|
||||
auto p = target.release();
|
||||
if (pImpl->composite(p, method)) return Result::Success;
|
||||
if (p) delete(p);
|
||||
return Result::InvalidArguments;
|
||||
}
|
||||
|
||||
|
|
|
@ -216,18 +216,24 @@ TEST_CASE("Paint Clip Path Composite Method", "[capiPaint]")
|
|||
REQUIRE(target);
|
||||
|
||||
REQUIRE(tvg_paint_set_composite_method(paint, NULL, TVG_COMPOSITE_METHOD_NONE) == TVG_RESULT_SUCCESS);
|
||||
REQUIRE(tvg_paint_set_composite_method(paint, target, TVG_COMPOSITE_METHOD_NONE) == TVG_RESULT_INVALID_ARGUMENT);
|
||||
|
||||
Tvg_Paint* target2 = tvg_shape_new();
|
||||
REQUIRE(target2);
|
||||
REQUIRE(tvg_paint_set_composite_method(paint, target2, TVG_COMPOSITE_METHOD_NONE) == TVG_RESULT_INVALID_ARGUMENT);
|
||||
|
||||
REQUIRE(tvg_paint_set_composite_method(paint, NULL, TVG_COMPOSITE_METHOD_CLIP_PATH) == TVG_RESULT_INVALID_ARGUMENT);
|
||||
REQUIRE(tvg_paint_set_composite_method(paint, target, TVG_COMPOSITE_METHOD_CLIP_PATH) == TVG_RESULT_SUCCESS);
|
||||
|
||||
const Tvg_Paint* target2 = nullptr;
|
||||
Tvg_Paint* target3 = tvg_shape_new();
|
||||
REQUIRE(target3);
|
||||
REQUIRE(tvg_paint_set_composite_method(paint, target3, TVG_COMPOSITE_METHOD_CLIP_PATH) == TVG_RESULT_SUCCESS);
|
||||
|
||||
const Tvg_Paint* target4 = nullptr;
|
||||
Tvg_Composite_Method method = TVG_COMPOSITE_METHOD_NONE;
|
||||
REQUIRE(tvg_paint_get_composite_method(paint, NULL, &method) == TVG_RESULT_INVALID_ARGUMENT);
|
||||
REQUIRE(tvg_paint_get_composite_method(paint, &target2, NULL) == TVG_RESULT_INVALID_ARGUMENT);
|
||||
REQUIRE(tvg_paint_get_composite_method(paint, &target2, &method) == TVG_RESULT_SUCCESS);
|
||||
REQUIRE(tvg_paint_get_composite_method(paint, &target4, NULL) == TVG_RESULT_INVALID_ARGUMENT);
|
||||
REQUIRE(tvg_paint_get_composite_method(paint, &target4, &method) == TVG_RESULT_SUCCESS);
|
||||
REQUIRE(method == TVG_COMPOSITE_METHOD_CLIP_PATH);
|
||||
REQUIRE(target == target2);
|
||||
REQUIRE(target3 == target4);
|
||||
|
||||
REQUIRE(tvg_paint_del(paint) == TVG_RESULT_SUCCESS);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue