From d69b1215231cfd24ec03035847fa7bac8d2bf740 Mon Sep 17 00:00:00 2001 From: cheng_jinsong Date: Fri, 14 Oct 2022 21:16:24 +0800 Subject: [PATCH] reboot loader Signed-off-by: cheng_jinsong --- interfaces/innerkits/modulemgr/modulemgr.c | 4 +++- services/modules/reboot/reboot_static.c | 4 ++-- test/unittest/init/init_reboot_unittest.cpp | 21 +++++++-------------- 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/interfaces/innerkits/modulemgr/modulemgr.c b/interfaces/innerkits/modulemgr/modulemgr.c index bbd81b1c..dcc077c4 100644 --- a/interfaces/innerkits/modulemgr/modulemgr.c +++ b/interfaces/innerkits/modulemgr/modulemgr.c @@ -224,7 +224,9 @@ static void ScanModules(MODULE_MGR *moduleMgr, const char *path) ModuleMgrInstall(moduleMgr, moduleName, 0, NULL); } } - free(moduleName); + if (moduleName != NULL) { + free(moduleName); + } closedir(dir); } diff --git a/services/modules/reboot/reboot_static.c b/services/modules/reboot/reboot_static.c index 487ddc5d..7263ffbe 100644 --- a/services/modules/reboot/reboot_static.c +++ b/services/modules/reboot/reboot_static.c @@ -68,7 +68,7 @@ static int CheckParamCmdExist(const char *cmd) char *cmdName = Dup2String(REBOOT_CMD_PREFIX, cmd); PLUGIN_CHECK(cmdName != NULL, return 0, "Failed to copy %s", cmd); for (int i = 0; i < g_rebootParamCmdValidNumber; i++) { - if (strcmp(g_rebootParamCmdInfos[i].cmd, cmdName) == 0){ + if (strcmp(g_rebootParamCmdInfos[i].cmd, cmdName) == 0) { free(cmdName); return 1; } @@ -160,4 +160,4 @@ MODULE_CONSTRUCTOR(void) { // 执行reboot时调用,安装reboot模块 InitAddRebootHook(InitRebootHook_); -} \ No newline at end of file +} diff --git a/test/unittest/init/init_reboot_unittest.cpp b/test/unittest/init/init_reboot_unittest.cpp index 4be58ab1..503a6026 100644 --- a/test/unittest/init/init_reboot_unittest.cpp +++ b/test/unittest/init/init_reboot_unittest.cpp @@ -39,17 +39,14 @@ public: static int g_result = 0; HWTEST_F(InitRebootUnitTest, TestAddRebootCmd, TestSize.Level1) { - int ret = AddRebootCmdExecutor("reboot_cmd1", [](int id, const char *name, int argc, const char **argv)-> int { + auto rebootCallback = [](int id, const char *name, int argc, const char **argv) -> int { return 0; - }); + } + int ret = AddRebootCmdExecutor("reboot_cmd1", rebootCallback); EXPECT_EQ(ret, 0); - ret = AddRebootCmdExecutor("reboot_cmd2", [](int id, const char *name, int argc, const char **argv)-> int { - return 0; - }); + ret = AddRebootCmdExecutor("reboot_cmd2", rebootCallback); EXPECT_EQ(ret, 0); - ret = AddRebootCmdExecutor("reboot_cmd3", [](int id, const char *name, int argc, const char **argv)-> int { - return 0; - }); + ret = AddRebootCmdExecutor("reboot_cmd3", rebootCallback); EXPECT_EQ(ret, 0); ret = AddRebootCmdExecutor("reboot_cmd4", [](int id, const char *name, int argc, const char **argv)-> int { g_result = 4; // 4 test index @@ -66,13 +63,9 @@ HWTEST_F(InitRebootUnitTest, TestAddRebootCmd, TestSize.Level1) return 0; }); EXPECT_EQ(ret, 0); - ret = AddRebootCmdExecutor("reboot_cmd7", [](int id, const char *name, int argc, const char **argv)-> int { - return 0; - }); + ret = AddRebootCmdExecutor("reboot_cmd7", rebootCallback); EXPECT_EQ(ret, 0); - ret = AddRebootCmdExecutor("reboot_cmd7", [](int id, const char *name, int argc, const char **argv)-> int { - return 0; - }); + ret = AddRebootCmdExecutor("reboot_cmd7", rebootCallback); EXPECT_NE(ret, 0); TestSetParamCheckResult("ohos.servicectrl.reboot", 0777, 0); -- GitLab