fix a memory leak to input feeding data
authorInki Dae <inki.dae@samsung.com>
Thu, 14 Mar 2024 01:30:01 +0000 (10:30 +0900)
committerInki Dae <inki.dae@samsung.com>
Thu, 14 Mar 2024 01:30:01 +0000 (10:30 +0900)
Fix a memory leak issue when pusing input feeding data to
incoming queue is skipped.

If the input feeding data was skipped then we have to release
the input feeding data which is a new buffer allocated and copied from
original data.

Signed-off-by: Inki Dae <inki.dae@samsung.com>
services/auto_zoom/src/AutoZoom.cpp
services/common/include/AsyncManager.h

index e606486adc98c6fbcbf119bdf76f8803263b94dc..c5ec66fed5194c2fbcb5cec666ccf1a71344ee8c 100644 (file)
@@ -70,7 +70,9 @@ void AutoZoom::inputServiceCb(ISingleoCommonData &data, void *user_data)
        copied.ptr = new unsigned char[buffer_size];
        memcpy(copied.ptr, preprocessed.ptr, buffer_size);
 
-       auto_zoom->getAsyncManager()->pushInput(copied);
+       // Make sure to release copied buffer if incoming queue isn't empty so skipped pushing the buffer.
+       if (auto_zoom->getAsyncManager()->pushInput(copied) < 0)
+               delete copied.ptr;
 }
 
 bool AutoZoom::isKeyValid(std::string key)
index 7e84a45c7b1f8941ef0de7380042dd9211f7d49c..f3fe5b7b36a9675ea7288eb0185a221f47cce580 100644 (file)
@@ -132,7 +132,7 @@ public:
 
        // This function will be called by specific input service internally.
        // Ps. caller has to provide captured data with concrete class object as data parameter.
-       void pushInput(In &in_data)
+       int pushInput(In &in_data)
        {
                // This callback will be called by platform specific input feed module.
                // The input feed module calls this callback with captured data after capturing data such as
@@ -148,10 +148,12 @@ public:
                // If input data exists in incoming queue then skip a new one.
                // TODO. consider for multiple input data later.
                if (!_incoming_queue.empty())
-                       return;
+                       return -1;
 
                _incoming_queue.push(in_data);
                _incoming_queue_event.notify_one();
+
+               return 0;
        }
 
        void pushOutput(Out &result)