From fc1bb751bf017fa755891925472a02a4fad8d121 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=83=B3=E4=B8=8D=E5=87=BA=E5=88=AB=E5=90=8D?= Date: Mon, 13 Sep 2021 11:02:38 +0800 Subject: [PATCH 1/2] =?UTF-8?q?FreeBuffer=20=E5=BD=92=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 想不出别名 --- .../native_cpp/src/ipc/lite/ipc_client_stub.cpp | 8 ++++++-- .../native_cpp/src/ipc/lite/ipc_cmd_parser.cpp | 10 ---------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_client_stub.cpp b/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_client_stub.cpp index 9ae99e19a..c24231546 100644 --- a/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_client_stub.cpp +++ b/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_client_stub.cpp @@ -36,8 +36,12 @@ static int32_t ClientIpcInterfaceMsgHandle(const IpcContext *ctx, void *ipcMsg, uint32_t code = 0; GetCode(ipcMsg, &code); - DMLOG(DM_LOG_INFO, "receive ipc transact code(%u)", code); - return IpcCmdRegister::GetInstance().OnIpcCmd(code, *io, *ctx, ipcMsg); + int32_t errCode = DEVICEMANAGER_OK; + + errCode = IpcCmdRegister::GetInstance().OnIpcCmd(code, *io, *ctx, ipcMsg); + DMLOG(DM_LOG_INFO, "receive ipc transact code:%u, retCode=%d", code, errCode); + FreeBuffer(ctx, ipcMsg); + return errCode; } int32_t IpcClientStub::Init() diff --git a/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_cmd_parser.cpp b/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_cmd_parser.cpp index 79dc594be..5a54bd6f5 100644 --- a/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_cmd_parser.cpp +++ b/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_cmd_parser.cpp @@ -191,7 +191,6 @@ ON_IPC_CMD(SERVER_DEVICE_STATE_NOTIFY, IpcIo &reply, const IpcContext &ctx, void const DmDeviceInfo *deviceInfo = (const DmDeviceInfo*)IpcIoPopFlatObj(&reply, &size); if (pkgName == "" || len == 0 || deviceInfo == NULL) { DMLOG(DM_LOG_ERROR, "OnDeviceOnline, get para failed"); - FreeBuffer(&ctx, ipcMsg); return; } switch (deviceState) { @@ -208,7 +207,6 @@ ON_IPC_CMD(SERVER_DEVICE_STATE_NOTIFY, IpcIo &reply, const IpcContext &ctx, void DMLOG(DM_LOG_ERROR, "unknown device state:%d", deviceState); break; } - FreeBuffer(&ctx, ipcMsg); } ON_IPC_CMD(SERVER_DEVICE_FOUND, IpcIo &reply, const IpcContext &ctx, void *ipcMsg) @@ -220,11 +218,9 @@ ON_IPC_CMD(SERVER_DEVICE_FOUND, IpcIo &reply, const IpcContext &ctx, void *ipcMs const DmDeviceInfo *deviceInfo = (const DmDeviceInfo*)IpcIoPopFlatObj(&reply, &size); if (pkgName == "" || len == 0 || deviceInfo == NULL) { DMLOG(DM_LOG_ERROR, "OnDeviceChanged, get para failed"); - FreeBuffer(&ctx, ipcMsg); return; } DeviceManagerNotify::GetInstance().OnDeviceFound(pkgName, subscribeId, *deviceInfo); - FreeBuffer(&ctx, ipcMsg); } ON_IPC_CMD(SERVER_DISCOVER_FINISH, IpcIo &reply, const IpcContext &ctx, void *ipcMsg) @@ -236,7 +232,6 @@ ON_IPC_CMD(SERVER_DISCOVER_FINISH, IpcIo &reply, const IpcContext &ctx, void *ip if (pkgName == "" || len == 0) { DMLOG(DM_LOG_ERROR, "OnDiscoverySuccess, get para failed"); - FreeBuffer(&ctx, ipcMsg); return; } if (failedReason == DEVICEMANAGER_OK) { @@ -244,7 +239,6 @@ ON_IPC_CMD(SERVER_DISCOVER_FINISH, IpcIo &reply, const IpcContext &ctx, void *ip } else { DeviceManagerNotify::GetInstance().OnDiscoverFailed(pkgName, subscribeId, failedReason); } - FreeBuffer(&ctx, ipcMsg); } ON_IPC_CMD(SERVER_AUTH_RESULT, IpcIo &reply, const IpcContext &ctx, void *ipcMsg) @@ -259,11 +253,9 @@ ON_IPC_CMD(SERVER_AUTH_RESULT, IpcIo &reply, const IpcContext &ctx, void *ipcMsg if (pkgName == "" || len == 0 || deviceId == "" || devIdLen == 0) { DMLOG(DM_LOG_ERROR, "OnAuthResult, get para failed"); - FreeBuffer(&ctx, ipcMsg); return; } DeviceManagerNotify::GetInstance().OnAuthResult(pkgName, deviceId, pinToken, status, reason); - FreeBuffer(&ctx, ipcMsg); } ON_IPC_CMD(SERVER_CHECK_AUTH_RESULT, IpcIo &reply, const IpcContext &ctx, void *ipcMsg) @@ -277,11 +269,9 @@ ON_IPC_CMD(SERVER_CHECK_AUTH_RESULT, IpcIo &reply, const IpcContext &ctx, void * if (pkgName == "" || len == 0 || deviceId == "" || devIdLen == 0) { DMLOG(DM_LOG_ERROR, "OnAuthResult, get para failed"); - FreeBuffer(&ctx, ipcMsg); return; } DeviceManagerNotify::GetInstance().OnCheckAuthResult(pkgName, deviceId, resultCode, flag); - FreeBuffer(&ctx, ipcMsg); } } // namespace DistributedHardware } // namespace OHOS -- Gitee From 20b075b3cd523af9945b3da03b14211eed03adbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=83=B3=E4=B8=8D=E5=87=BA=E5=88=AB=E5=90=8D?= Date: Mon, 13 Sep 2021 11:46:28 +0800 Subject: [PATCH 2/2] =?UTF-8?q?FreeBuffer=20=E5=BD=92=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 想不出别名 --- .../src/ipc/lite/ipc_cmd_parser.cpp | 6 ++-- .../src/ipc/lite/ipc_server_stub.cpp | 31 +++++++------------ 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/services/devicemanagerservice/src/ipc/lite/ipc_cmd_parser.cpp b/services/devicemanagerservice/src/ipc/lite/ipc_cmd_parser.cpp index b4e185050..3dc56c22b 100644 --- a/services/devicemanagerservice/src/ipc/lite/ipc_cmd_parser.cpp +++ b/services/devicemanagerservice/src/ipc/lite/ipc_cmd_parser.cpp @@ -159,12 +159,14 @@ ON_IPC_SERVER_CMD(GET_TRUST_DEVICE_LIST, IpcIo &req, IpcIo &reply) ON_IPC_SERVER_CMD(REGISTER_DEVICE_MANAGER_LISTENER, IpcIo &req, IpcIo &reply) { - RegisterDeviceManagerListener(&req, &reply); + int32_t errCode = RegisterDeviceManagerListener(&req, &reply); + IpcIoPushInt32(&reply, errCode); } ON_IPC_SERVER_CMD(UNREGISTER_DEVICE_MANAGER_LISTENER, IpcIo &req, IpcIo &reply) { - UnRegisterDeviceManagerListener(&req, &reply); + int32_t errCode = UnRegisterDeviceManagerListener(&req, &reply); + IpcIoPushInt32(&reply, errCode); } ON_IPC_SERVER_CMD(START_DEVICE_DISCOVER, IpcIo &req, IpcIo &reply) diff --git a/services/devicemanagerservice/src/ipc/lite/ipc_server_stub.cpp b/services/devicemanagerservice/src/ipc/lite/ipc_server_stub.cpp index 775245f59..1cb044337 100644 --- a/services/devicemanagerservice/src/ipc/lite/ipc_server_stub.cpp +++ b/services/devicemanagerservice/src/ipc/lite/ipc_server_stub.cpp @@ -77,7 +77,6 @@ static int32_t DeathCb(const IpcContext *context, void *ipcMsg, IpcIo *data, voi sid.token = svcId.token; sid.cookie = svcId.cookie; UnregisterDeathCallback(sid, svcId.cbId); - return DEVICEMANAGER_OK; } @@ -85,13 +84,11 @@ int32_t RegisterDeviceManagerListener(IpcIo *req, IpcIo *reply) { DMLOG(DM_LOG_INFO, "register service listener."); size_t len = 0; - int32_t ret = DEVICEMANAGER_OK; uint8_t *name = IpcIoPopString(req, &len); SvcIdentity *svc = IpcIoPopSvc(req); if (name == NULL || svc == NULL || len == 0) { DMLOG(DM_LOG_ERROR, "get para failed"); - IpcIoPushInt32(reply, ret); - return DEVICEMANAGER_OK; + return DEVICEMANAGER_INVALID_PARAM; } CommonSvcId svcId = {0}; @@ -106,26 +103,21 @@ int32_t RegisterDeviceManagerListener(IpcIo *req, IpcIo *reply) free(svc); svc = NULL; #endif - char *pkgName = (char *)malloc(len + 1); if (pkgName == NULL) { DMLOG(DM_LOG_ERROR, "malloc failed!"); - IpcIoPushInt32(reply, DEVICEMANAGER_FAILED); - return DEVICEMANAGER_FAILED; + return DEVICEMANAGER_MALLOC_ERROR; } if (strcpy_s(pkgName, len + 1, (const char *)name) != DEVICEMANAGER_OK) { DMLOG(DM_LOG_ERROR, "strcpy_s failed!"); free(pkgName); - IpcIoPushInt32(reply, DEVICEMANAGER_FAILED); - return DEVICEMANAGER_FAILED; + return DEVICEMANAGER_COPY_FAILED; } uint32_t cbId = 0; RegisterDeathCallback(NULL, sid, DeathCb, pkgName, &cbId); svcId.cbId = cbId; std::string strPkgName = (const char *)name; - ret = IpcServerListenermgr::GetInstance().RegisterListener(strPkgName, &svcId); - IpcIoPushInt32(reply, ret); - return DEVICEMANAGER_OK; + return IpcServerListenermgr::GetInstance().RegisterListener(strPkgName, &svcId); } int32_t UnRegisterDeviceManagerListener(IpcIo *req, IpcIo *reply) @@ -138,24 +130,23 @@ int32_t UnRegisterDeviceManagerListener(IpcIo *req, IpcIo *reply) return DEVICEMANAGER_FAILED; } - CommonSvcId svcId = {0}; - if (IpcServerListenermgr::GetInstance().GetListenerByPkgName(pkgName, &svcId) != DEVICEMANAGER_OK) { - DMLOG(DM_LOG_ERROR, "not found listener by package name."); - return DEVICEMANAGER_FAILED; - } int32_t ret = IpcServerListenermgr::GetInstance().UnregisterListener(pkgName); if (ret == DEVICEMANAGER_OK) { + CommonSvcId svcId; + if (IpcServerListenermgr::GetInstance().GetListenerByPkgName(pkgName, &svcId) != DEVICEMANAGER_OK) { + DMLOG(DM_LOG_ERROR, "not found listener by package name."); + return DEVICEMANAGER_FAILED; + } #ifdef __LINUX__ BinderRelease(svcId.ipcCtx, svcId.handle); #endif - SvcIdentity sid = {0}; + SvcIdentity sid; sid.handle = svcId.handle; sid.token = svcId.token; sid.cookie = svcId.cookie; ret = UnregisterDeathCallback(sid, svcId.cbId); } - IpcIoPushInt32(reply, ret); - return DEVICEMANAGER_OK; + return ret; } static const char *GetName(Service *service) -- Gitee