[Bug/Fix] Don't access request instance after callback
authorDongju Chae <dongju.chae@samsung.com>
Tue, 10 Aug 2021 06:31:02 +0000 (15:31 +0900)
committer채동주/On-Device Lab(SR)/Staff Engineer/삼성전자 <dongju.chae@samsung.com>
Tue, 10 Aug 2021 07:51:22 +0000 (16:51 +0900)
This patch fixes double free bug. The callback handler
should not access the request instance after user callback.

Signed-off-by: Dongju Chae <dongju.chae@samsung.com>
src/core/ne-handler.cc

index 74521ad..e985418 100644 (file)
@@ -1172,12 +1172,11 @@ TrinityVision2::callback (Request *req, npuOutputNotify cb, void *cb_data) {
   assert (model != nullptr);
   assert (segt != nullptr);
 
+  output_buffers default_output = {0};
   output_buffers *output = req->getOutputBuffers ();
   /* user didn't provide valid output buffers. So, pass internally allocated one */
-  if (output == nullptr) {
-    output = new output_buffers;
-    memset (output, '\x00', sizeof (output_buffers));
-  }
+  if (output == nullptr)
+    output = &default_output;
   if (output->num_buffers == 0)
     output->num_buffers = segt->getNumOutputSegments ();
 
@@ -1226,9 +1225,6 @@ TrinityVision2::callback (Request *req, npuOutputNotify cb, void *cb_data) {
   }
 
   cb (output, req->getID (), cb_data);
-
-  if (req->getOutputBuffers () != output)
-    delete output;
 }
 
 int