[arrayfire] 218/248: Memory leak fix in SUSAN feature detector
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Tue Nov 17 15:54:29 UTC 2015
This is an automated email from the git hooks/post-receive script.
ghisvail-guest pushed a commit to branch dfsg-clean
in repository arrayfire.
commit 2a21ddce1045cb578b5bb934778772db50a98425
Author: pradeep <pradeep at arrayfire.com>
Date: Tue Nov 10 11:40:57 2015 -0500
Memory leak fix in SUSAN feature detector
---
src/api/c/susan.cpp | 7 ++-----
src/backend/cpu/susan.cpp | 19 +++++++++++++------
src/backend/cuda/susan.cu | 20 +++++++++++++-------
src/backend/opencl/susan.cpp | 20 +++++++++++++-------
4 files changed, 41 insertions(+), 25 deletions(-)
diff --git a/src/api/c/susan.cpp b/src/api/c/susan.cpp
index 24cb913..75c2953 100644
--- a/src/api/c/susan.cpp
+++ b/src/api/c/susan.cpp
@@ -34,14 +34,11 @@ static af_features susan(af_array const &in,
getArray<T>(in), radius, diff_thr, geom_thr,
feature_ratio, edge);
- Array<float> orientation = createValueArray<float>(feat.n, 0.0);
- Array<float> size = createValueArray<float>(feat.n, 1.0);
-
feat.x = getHandle(x);
feat.y = getHandle(y);
feat.score = getHandle(score);
- feat.orientation = getHandle(orientation);
- feat.size = getHandle(size);
+ feat.orientation = getHandle(feat.n > 0 ? createValueArray<float>(feat.n, 0.0) : createEmptyArray<float>(dim4()));
+ feat.size = getHandle(feat.n > 0 ? createValueArray<float>(feat.n, 1.0) : createEmptyArray<float>(dim4()));
return getFeaturesHandle(feat);
}
diff --git a/src/backend/cpu/susan.cpp b/src/backend/cpu/susan.cpp
index 458577f..7749391 100644
--- a/src/backend/cpu/susan.cpp
+++ b/src/backend/cpu/susan.cpp
@@ -111,14 +111,21 @@ unsigned susan(Array<float> &x_out, Array<float> &y_out, Array<float> &resp_out,
memFree(resp);
const unsigned corners_out = min(corners_found, corner_lim);
- if (corners_out == 0)
+ if (corners_out == 0) {
+ memFree(x_corners);
+ memFree(y_corners);
+ memFree(resp_corners);
+ x_out = createEmptyArray<float>(dim4());
+ y_out = createEmptyArray<float>(dim4());
+ resp_out = createEmptyArray<float>(dim4());
return 0;
+ } else {
- x_out = createDeviceDataArray<float>(dim4(corners_out), (void*)x_corners);
- y_out = createDeviceDataArray<float>(dim4(corners_out), (void*)y_corners);
- resp_out = createDeviceDataArray<float>(dim4(corners_out), (void*)resp_corners);
-
- return corners_out;
+ x_out = createDeviceDataArray<float>(dim4(corners_out), (void*)x_corners);
+ y_out = createDeviceDataArray<float>(dim4(corners_out), (void*)y_corners);
+ resp_out = createDeviceDataArray<float>(dim4(corners_out), (void*)resp_corners);
+ return corners_out;
+ }
}
#define INSTANTIATE(T) \
diff --git a/src/backend/cuda/susan.cu b/src/backend/cuda/susan.cu
index 6925d0c..f79e07a 100644
--- a/src/backend/cuda/susan.cu
+++ b/src/backend/cuda/susan.cu
@@ -42,14 +42,20 @@ unsigned susan(Array<float> &x_out, Array<float> &y_out, Array<float> &resp_out,
memFree(resp);
const unsigned corners_out = min(corners_found, corner_lim);
- if (corners_out == 0)
+ if (corners_out == 0) {
+ memFree(x_corners);
+ memFree(y_corners);
+ memFree(resp_corners);
+ x_out = createEmptyArray<float>(dim4());
+ y_out = createEmptyArray<float>(dim4());
+ resp_out = createEmptyArray<float>(dim4());
return 0;
-
- x_out = createDeviceDataArray<float>(dim4(corners_out), (void*)x_corners);
- y_out = createDeviceDataArray<float>(dim4(corners_out), (void*)y_corners);
- resp_out = createDeviceDataArray<float>(dim4(corners_out), (void*)resp_corners);
-
- return corners_out;
+ } else {
+ x_out = createDeviceDataArray<float>(dim4(corners_out), (void*)x_corners);
+ y_out = createDeviceDataArray<float>(dim4(corners_out), (void*)y_corners);
+ resp_out = createDeviceDataArray<float>(dim4(corners_out), (void*)resp_corners);
+ return corners_out;
+ }
}
#define INSTANTIATE(T) \
diff --git a/src/backend/opencl/susan.cpp b/src/backend/opencl/susan.cpp
index 52a63b4..b390566 100644
--- a/src/backend/opencl/susan.cpp
+++ b/src/backend/opencl/susan.cpp
@@ -51,14 +51,20 @@ unsigned susan(Array<float> &x_out, Array<float> &y_out, Array<float> &resp_out,
bufferFree(resp);
const unsigned corners_out = std::min(corners_found, corner_lim);
- if (corners_out == 0)
+ if (corners_out == 0) {
+ bufferFree(x_corners);
+ bufferFree(y_corners);
+ bufferFree(resp_corners);
+ x_out = createEmptyArray<float>(dim4());
+ y_out = createEmptyArray<float>(dim4());
+ resp_out = createEmptyArray<float>(dim4());
return 0;
-
- x_out = createDeviceDataArray<float>(dim4(corners_out), (void*)((*x_corners)()));
- y_out = createDeviceDataArray<float>(dim4(corners_out), (void*)((*y_corners)()));
- resp_out = createDeviceDataArray<float>(dim4(corners_out), (void*)((*resp_corners)()));
-
- return corners_out;
+ } else {
+ x_out = createDeviceDataArray<float>(dim4(corners_out), (void*)((*x_corners)()));
+ y_out = createDeviceDataArray<float>(dim4(corners_out), (void*)((*y_corners)()));
+ resp_out = createDeviceDataArray<float>(dim4(corners_out), (void*)((*resp_corners)()));
+ return corners_out;
+ }
}
#define INSTANTIATE(T) \
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/arrayfire.git
More information about the debian-science-commits
mailing list