check of nullptr and return value of sprintf_s

Signed-off-by: surencong <surencong@huawei.com>
Change-Id: I48acb0ef1d6204e9ae618b99df12cfd9b6a17394
This commit is contained in:
surencong 2023-12-12 14:09:52 +08:00
parent 311adae5c0
commit e2a23a15e1

View File

@ -40,10 +40,17 @@ static bool g_enableSandbox = false;
static void WriteOomScoreAdjToService(Service *service)
{
if (service == NULL) {
return;
}
if (IsOnDemandService(service)) {
char pidAdjPath[30];
const char* content = "-900";
sprintf_s(pidAdjPath, sizeof(pidAdjPath), "/proc/%d/oom_score_adj", service->pid);
int len = sprintf_s(pidAdjPath, sizeof(pidAdjPath), "/proc/%d/oom_score_adj", service->pid);
if (len <= 0) {
INIT_LOGE("Service(%s): format pidAdjPath (pid:%d) failed.", service->name, service->pid);
return;
}
int fd = open(pidAdjPath, O_RDWR);
if (fd < 0) {
INIT_LOGE("Service(%s): open path %s failed.", service->name, pidAdjPath);