From aaed15a2e131f97423095ea0e459a0fa8b2b9ae4 Mon Sep 17 00:00:00 2001 From: Falk David Date: Thu, 7 Dec 2023 17:34:53 +0100 Subject: [PATCH] Fix: GPv3: Crash when drawing The commit cad81786d01cfd4fdf68cba0e853f48f3749fb24 introduced a crash. The memory from `curve_fit_cubic_to_points_fl` and `curve_fit_corners_detect_fl` needs to be freed with `free` and we need to check for `nullptr`. --- .../grease_pencil/intern/grease_pencil_geom.cc | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/source/blender/editors/grease_pencil/intern/grease_pencil_geom.cc b/source/blender/editors/grease_pencil/intern/grease_pencil_geom.cc index 5ecebdd849a..57a3066266f 100644 --- a/source/blender/editors/grease_pencil/intern/grease_pencil_geom.cc +++ b/source/blender/editors/grease_pencil/intern/grease_pencil_geom.cc @@ -117,11 +117,15 @@ Array polyline_fit_curve(Span points, return {}; } + if (r_cubic_array == nullptr) { + return {}; + } + Span r_cubic_array_span(reinterpret_cast(r_cubic_array), r_cubic_array_len * 3); Array curve_positions(r_cubic_array_span); /* Free the c-style array. */ - MEM_freeN(r_cubic_array); + free(r_cubic_array); return curve_positions; } @@ -153,11 +157,16 @@ IndexMask polyline_detect_corners(Span points, /* Error occurred, return. */ return IndexMask(); } + + if (r_corners == nullptr) { + return IndexMask(); + } + BLI_assert(samples_max < std::numeric_limits::max()); Span indices(reinterpret_cast(r_corners), r_corner_len); const IndexMask corner_mask = IndexMask::from_indices(indices, memory); /* Free the c-style array. */ - MEM_freeN(r_corners); + free(r_corners); return corner_mask; }