[M108 Migration] Fix memory leak in intercept request 84/289384/2
authorfeifei08.liu <feifei08.liu@samsung.com>
Tue, 7 Mar 2023 02:04:40 +0000 (10:04 +0800)
committerBot Blink <blinkbot@samsung.com>
Mon, 13 Mar 2023 07:10:34 +0000 (07:10 +0000)
In TV plus test case, HBB team found some memory from ewk intercept
request interface have never been released.
Test case: Repeatly raise Tv plus and exit.

hbbtv_app process never exit, each time raising Tv plus, many ewk intercept
request instances and ProxyingURLLoaderEfl instances will be leaked:
1. In ProxyingURLLoaderFactoryEfl::CreateLoaderAndStart,
   when intercept_request->is_ignored(),
   the new _Ewk_Intercept_Request will be leak;
2. In ProxyingURLLoaderFactoryEfl::CreateLoaderAndStart,
   after creating, the created ProxyingURLLoaderEfl never dtor;
3. In _Ewk_Intercept_Request::put_chunk, when delegate_ is null,
   the function input "char* data" will be leaked.
4. In ProxyingURLLoaderEfl::PutChunk, the instance dose not emplace
   the input data memory nor delete it.

Reference:
- https://review.tizen.org/gerrit/283460/

Change-Id: Icb5d95ea5e201e9f8beb24914b14822b2e99957e
Signed-off-by: feifei08.liu <feifei08.liu@samsung.com>
tizen_src/ewk/efl_integration/browser/network_service/proxying_url_loader_efl.cc
tizen_src/ewk/efl_integration/private/ewk_intercept_request_private.cc

index a7c85f9..8c0f547 100644 (file)
@@ -82,6 +82,8 @@ void ProxyingURLLoaderEfl::ResponseDecided() {
 
 void ProxyingURLLoaderEfl::PutChunk(const char* data, size_t length) {
   AddRawDataIntoBuffer(data, length);
+  if (data)
+    delete data;
 }
 
 void ProxyingURLLoaderEfl::ChunkedReadDone() {
@@ -156,6 +158,7 @@ void ProxyingURLLoaderEfl::Finish(int error) {
   client_->OnComplete(network::URLLoaderCompletionStatus(error));
   producer_handle_watcher_.reset();
   producer_handle_.reset();
+  binding_.reset();
   client_.reset();
   weak_ptr_factory_.InvalidateWeakPtrs();
   MaybeDeleteSelf();
index 8f71d28..abde5aa 100644 (file)
@@ -167,6 +167,8 @@ void _Ewk_Intercept_Request::post_response_decided() {
 void _Ewk_Intercept_Request::put_chunk(const char* data, size_t length) {
   if (delegate_)
     delegate_->PutChunk(data, length);
+  else
+    delete data;
 }
 
 void _Ewk_Intercept_Request::post_put_chunk(const char* data, size_t length) {