From 0d270844a6b7c9153b510662ab71e0d9005d1dd9 Mon Sep 17 00:00:00 2001 From: Daljit Singh Date: Tue, 28 Nov 2023 23:49:45 +0000 Subject: [PATCH] Fix memory leak in sh2peaks The precomputer instance in Processor was allocated as a raw pointer and thus never freed. --- cmd/sh2peaks.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/sh2peaks.cpp b/cmd/sh2peaks.cpp index ed28267904..5ccd286811 100644 --- a/cmd/sh2peaks.cpp +++ b/cmd/sh2peaks.cpp @@ -157,7 +157,7 @@ class Processor { threshold(threshold), peaks_out(npeaks), ipeaks_vox(ipeaks_data), - precomputer(use_precomputer ? new Math::SH::PrecomputedAL(lmax) : nullptr) {} + precomputer(use_precomputer ? std::make_shared>(lmax) : nullptr) {} bool operator()(const Item &item) { @@ -175,7 +175,7 @@ class Processor { for (size_t i = 0; i < size_t(dirs.rows()); i++) { Direction p(dirs(i, 0), dirs(i, 1)); - p.a = Math::SH::get_peak(item.data, lmax, p.v, precomputer); + p.a = Math::SH::get_peak(item.data, lmax, p.v, precomputer.get()); if (std::isfinite(p.a)) { for (size_t j = 0; j < all_peaks.size(); j++) { if (abs(p.v.dot(all_peaks[j].v)) > DOT_THRESHOLD) { @@ -249,7 +249,7 @@ class Processor { value_type threshold; vector peaks_out; Image ipeaks_vox; - Math::SH::PrecomputedAL *precomputer; + std::shared_ptr> precomputer; bool check_input(const Item &item) { if (ipeaks_vox.valid()) {