[tensor_filter_nntrainer] Set custom deleter to unique_ptr accepted/tizen/unified/20210324.124300 submit/tizen/20210324.050003 submit/tizen/20210324.062722
authorhyeonseok lee <hs89.lee@samsung.com>
Tue, 23 Mar 2021 09:05:41 +0000 (18:05 +0900)
committerJijoong Moon <jijoong.moon@samsung.com>
Tue, 23 Mar 2021 10:46:02 +0000 (19:46 +0900)
g_new() should match with g_malloc instread delete
Refer to https://developer.gnome.org/glib/stable/glib-Memory-Allocation.html
It handles HEAP_INCOMPATIBLE.FREE issue
resolves: 458008, 458009

Signed-off-by: hyeonseok lee <hs89.lee@samsung.com>
nnstreamer/tensor_filter/tensor_filter_nntrainer.cc

index fa34cd0e624dc03c221f0865084eb9b62f3808fa..ab881519257518e0c8e2900f8428160ff76ede07 100644 (file)
@@ -46,9 +46,16 @@ static const gchar *nntrainer_accl_support[] = {NULL};
 void init_filter_nntrainer(void) __attribute__((constructor));
 void fini_filter_nntrainer(void) __attribute__((destructor));
 
-static std::unique_ptr<GstTensorInfo>
+struct gNewDeletor {
+    template <typename T>
+    void operator()(T* ptr) const {
+        g_free(ptr);
+    }
+};
+
+static std::unique_ptr<GstTensorInfo, gNewDeletor>
 to_nnst_tensor_dim(const nntrainer::TensorDim &dim) {
-  auto info = std::unique_ptr<GstTensorInfo>(g_new(GstTensorInfo, 1));
+  auto info = std::unique_ptr<GstTensorInfo, gNewDeletor>(g_new(GstTensorInfo, 1));
   gst_tensor_info_init(info.get());
 
   info->type = _NNS_FLOAT32;