Fix: GPv3: Crash when drawing

The commit cad81786d0 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`.
This commit is contained in:
Falk David
2023-12-07 17:34:53 +01:00
parent 3360b6344f
commit aaed15a2e1

View File

@@ -117,11 +117,15 @@ Array<float2> polyline_fit_curve(Span<float2> points,
return {};
}
if (r_cubic_array == nullptr) {
return {};
}
Span<float2> r_cubic_array_span(reinterpret_cast<float2 *>(r_cubic_array),
r_cubic_array_len * 3);
Array<float2> 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<float2> points,
/* Error occurred, return. */
return IndexMask();
}
if (r_corners == nullptr) {
return IndexMask();
}
BLI_assert(samples_max < std::numeric_limits<int>::max());
Span<int> indices(reinterpret_cast<int *>(r_corners), r_corner_len);
const IndexMask corner_mask = IndexMask::from_indices<int>(indices, memory);
/* Free the c-style array. */
MEM_freeN(r_corners);
free(r_corners);
return corner_mask;
}