From 0afd8ab26c94e1bd1de4152e14c9a5b22dd33f52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=B5=A9?= Date: Fri, 25 Jul 2025 19:47:51 +0800 Subject: [PATCH] clear child msg MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 杨浩 --- standard/appspawn_service.c | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/standard/appspawn_service.c b/standard/appspawn_service.c index b53f56d7..ee6f58f1 100644 --- a/standard/appspawn_service.c +++ b/standard/appspawn_service.c @@ -699,6 +699,13 @@ static bool IsSupportRunHnp() static void ClearMMAP(int clientId, uint32_t memSize) { + AppSpawnContent *content = GetAppSpawnContent(); + if (content != NULL && content->propertyBuffer != NULL) { + int ret = munmap(content->propertyBuffer, memSize); + APPSPAWN_CHECK_ONLY_LOG(ret == 0, "munmap failed %{public}d %{public}d", ret, errno); + content->propertyBuffer = NULL; + } + char path[PATH_MAX] = {0}; int ret = snprintf_s(path, sizeof(path), sizeof(path) - 1, APPSPAWN_MSG_DIR "appspawn/prefork_%d", clientId); APPSPAWN_CHECK_ONLY_LOG(ret > 0, "snprintf failed with %{public}d %{public}d", ret, errno); @@ -706,12 +713,27 @@ static void ClearMMAP(int clientId, uint32_t memSize) ret = unlink(path); APPSPAWN_CHECK_ONLY_LOG(ret == 0, "prefork unlink result %{public}d %{public}d", ret, errno); } +} - AppSpawnContent *content = GetAppSpawnContent(); - if (content != NULL && content->propertyBuffer != NULL) { - ret = munmap(content->propertyBuffer, memSize); +static void ClearPreforkInfo(AppSpawningCtx *property) +{ + if (property == NULL) { + return; + } + + if (property->forkCtx.childMsg != NULL) { + int ret = munmap(property->forkCtx.childMsg, property->forkCtx.msgSize); APPSPAWN_CHECK_ONLY_LOG(ret == 0, "munmap failed %{public}d %{public}d", ret, errno); - content->propertyBuffer = NULL; + property->forkCtx.childMsg = NULL; + } + + char path[PATH_MAX] = {0}; + int ret = snprintf_s(path, sizeof(path), sizeof(path) - 1, APPSPAWN_MSG_DIR "appspawn/prefork_%d", + property->client.id); + APPSPAWN_CHECK_ONLY_LOG(ret > 0, "snprintf failed with %{public}d %{public}d", ret, errno); + if (ret > 0 && access(path, F_OK) == 0) { + ret = unlink(path); + APPSPAWN_CHECK_ONLY_LOG(ret == 0, "prefork unlink result %{public}d %{public}d", ret, errno); } } @@ -832,12 +854,12 @@ static void ProcessPreFork(AppSpawnContent *content, AppSpawningCtx *property) const uint32_t memSize = (preforkMsg.msgLen / MAX_MSG_BLOCK_LEN + 1) * MAX_MSG_BLOCK_LEN; if (GetAppSpawnMsg(property, memSize) == -1) { APPSPAWN_LOGE("prefork child read GetAppSpawnMsg failed"); - ClearMMAP(property->client.id, memSize); + ClearPreforkInfo(property); content->notifyResToParent(content, &property->client, APPSPAWN_MSG_INVALID); ProcessExit(0); return; } - ClearMMAP(property->client.id, memSize); + ClearPreforkInfo(property); // Inherit the error level of the original process (void)fdsan_set_error_level(errorLevel); ProcessExit(AppSpawnChild(content, &property->client)); -- Gitee