From: Inki Dae Date: Thu, 14 Mar 2024 01:30:01 +0000 (+0900) Subject: fix a memory leak to input feeding data X-Git-Tag: accepted/tizen/unified/20240903.110722~78^2~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a7fccea77a73bd8be4dc3e1987dfd4e295e6f0c7;p=platform%2Fcore%2Fapi%2Fsingleo.git fix a memory leak to input feeding data 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 --- diff --git a/services/auto_zoom/src/AutoZoom.cpp b/services/auto_zoom/src/AutoZoom.cpp index e606486..c5ec66f 100644 --- a/services/auto_zoom/src/AutoZoom.cpp +++ b/services/auto_zoom/src/AutoZoom.cpp @@ -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) diff --git a/services/common/include/AsyncManager.h b/services/common/include/AsyncManager.h index 7e84a45..f3fe5b7 100644 --- a/services/common/include/AsyncManager.h +++ b/services/common/include/AsyncManager.h @@ -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)