diff --git a/services/begetctl/dump_service.c b/services/begetctl/dump_service.c index 8ba1190449f4f7c959145acd4ad14be8caebd851..bb4ae5580a62daab0adfa9cd0553e71dc52d3354 100644 --- a/services/begetctl/dump_service.c +++ b/services/begetctl/dump_service.c @@ -37,6 +37,7 @@ static int main_cmd(BShellHandle shell, int argc, char **argv) } size_t serviceNameLen = strlen(argv[1]) + strlen(argv[2]) + 2; // 2 is \0 and # char *cmd = (char *)calloc(1, serviceNameLen); + BEGET_ERROR_CHECK(cmd != NULL, return 0, "failed to allocate cmd memory"); BEGET_ERROR_CHECK(sprintf_s(cmd, serviceNameLen, "%s#%s", argv[1], argv[2]) >= 0, free(cmd); return 0, "dump service arg create failed"); CmdClientInit(INIT_CONTROL_FD_SOCKET_PATH, ACTION_DUMP, cmd); diff --git a/test/unittest/init/service_unittest.cpp b/test/unittest/init/service_unittest.cpp index 076db042b2b7b4a23d5dd1a1489c27192658b287..4f89410a43ad858a6337ca5428cc71f8e9138e17 100644 --- a/test/unittest/init/service_unittest.cpp +++ b/test/unittest/init/service_unittest.cpp @@ -82,15 +82,18 @@ HWTEST_F(ServiceUnitTest, case02, TestSize.Level1) cJSON *serviceItem = cJSON_GetObjectItem(jobItem, "services"); ASSERT_NE(nullptr, serviceItem); Service *service = AddService("test_service8"); + ASSERT_NE(nullptr, service); int ret = ParseOneService(serviceItem, service); EXPECT_EQ(ret, 0); int *fds = (int *)malloc(sizeof(int) * 1); // ServiceStop will release fds + ASSERT_NE(nullptr, fds); UpdaterServiceFds(service, fds, 1); service->attribute = SERVICE_ATTR_ONDEMAND; ret = ServiceStart(service); EXPECT_EQ(ret, 0); CmdLines *cmdline = (CmdLines *)malloc(sizeof(CmdLines) + sizeof(CmdLine)); + ASSERT_NE(nullptr, cmdline); cmdline->cmdNum = 1; cmdline->cmds[0].cmdIndex = 0; service->restartArg = cmdline; @@ -213,20 +216,26 @@ HWTEST_F(ServiceUnitTest, TestServiceManagerRelease, TestSize.Level1) service = AddService("test_service5"); ASSERT_NE(nullptr, service); service->pathArgs.argv = (char **)malloc(sizeof(char *)); + ASSERT_NE(nullptr, service->pathArgs.argv); service->pathArgs.count = 1; const char *path = "/data/init_ut/test_service_release"; service->pathArgs.argv[0] = strdup(path); service->writePidArgs.argv = (char **)malloc(sizeof(char *)); + ASSERT_NE(nullptr, service->writePidArgs.argv); service->writePidArgs.count = 1; service->writePidArgs.argv[0] = strdup(path); service->servPerm.caps = (unsigned int *)malloc(sizeof(unsigned int)); + ASSERT_NE(nullptr, service->servPerm.caps); service->servPerm.gIDArray = (gid_t *)malloc(sizeof(gid_t)); + ASSERT_NE(nullptr, service->servPerm.gIDArray); service->socketCfg = (ServiceSocket *)malloc(sizeof(ServiceSocket)); + ASSERT_NE(nullptr, service->socketCfg); service->socketCfg->sockFd = 0; service->socketCfg->next = nullptr; service->fileCfg = (ServiceFile *)malloc(sizeof(ServiceFile)); + ASSERT_NE(nullptr, service->fileCfg); service->fileCfg->fd = 0; service->fileCfg->next = nullptr; ReleaseService(service); @@ -330,6 +339,7 @@ HWTEST_F(ServiceUnitTest, TestServiceExec, TestSize.Level1) service->servPerm.gIDCnt = -1; service->servPerm.uID = 0; unsigned int *caps = (unsigned int *)calloc(1, sizeof(unsigned int) * 1); + ASSERT_NE(nullptr, caps); caps[0] = FULL_CAP; service->servPerm.caps = caps; service->servPerm.capsCnt = 1; diff --git a/test/unittest/param/param_unittest.cpp b/test/unittest/param/param_unittest.cpp index 885ff1492e867172e3deacc000fa22018a485a2d..f263565334426b6277446849a9db592c50095f96 100644 --- a/test/unittest/param/param_unittest.cpp +++ b/test/unittest/param/param_unittest.cpp @@ -405,7 +405,9 @@ HWTEST_F(ParamUnitTest, TestLinuxRWLock, TestSize.Level0) ParamRWMutexDelete(nullptr); ParamMutexDelete(nullptr); WorkSpace *workspace1 = (WorkSpace *)malloc(sizeof(WorkSpace) + strlen("testfilename1")); + ASSERT_NE(nullptr, workspace1); WorkSpace *workspace2 = (WorkSpace *)malloc(sizeof(WorkSpace) + strlen("testfilename1")); + ASSERT_NE(nullptr, workspace2); if (strcpy_s(workspace1->fileName, strlen("testfilename1"), "testfilename") != EOK) { EXPECT_EQ(0, 1); }