!481 修复内存泄漏问题

Merge pull request !481 from 郑志豪/master
This commit is contained in:
openharmony_ci 2024-11-05 14:08:25 +00:00 committed by Gitee
commit 3cda3d3bc1
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 28 additions and 5 deletions

View File

@ -58,8 +58,13 @@ bool JsPrintCallback::Call(napi_env env, void *data, uv_after_work_cb afterCallb
return false;
}
work->data = data;
uv_queue_work_with_qos(
loop, work, [](uv_work_t *work) {}, afterCallback, uv_qos_user_initiated);
int retVal = uv_queue_work_with_qos(loop, work,
[](uv_work_t *work) {}, afterCallback, uv_qos_user_initiated);
if (retVal != 0) {
PRINT_HILOGE("Failed to create uv work");
delete work;
return false;
}
return true;
}

View File

@ -339,7 +339,13 @@ bool JsPrintExtension::Callback(std::string funcName)
delete param;
delete work;
};
JsPrintCallback::Call(env, workParam, afterCallback);
bool ret = JsPrintCallback::Call(env, workParam, afterCallback);
if (!ret) {
delete workParam;
workParam = nullptr;
PRINT_HILOGE("Callback fail, delete param");
return false;
}
return true;
}
@ -379,7 +385,13 @@ bool JsPrintExtension::Callback(const std::string funcName, const std::string &p
delete param;
delete work;
};
JsPrintCallback::Call(env, workParam, afterCallback);
bool ret = JsPrintCallback::Call(env, workParam, afterCallback);
if (!ret) {
delete workParam;
workParam = nullptr;
PRINT_HILOGE("Callback fail, delete param");
return false;
}
return true;
}
@ -419,7 +431,13 @@ bool JsPrintExtension::Callback(const std::string funcName, const Print::PrintJo
delete param;
delete work;
};
JsPrintCallback::Call(env, workParam, afterCallback);
bool ret = JsPrintCallback::Call(env, workParam, afterCallback);
if (!ret) {
delete workParam;
workParam = nullptr;
PRINT_HILOGE("Callback fail, delete param");
return false;
}
return true;
}