From e849f1414ed5b1f3c088bc219ba08b0d44e5aeac Mon Sep 17 00:00:00 2001 From: George Burgess IV Date: Thu, 5 Aug 2021 06:59:42 +0000 Subject: [PATCH] lmkd: fix potential NULL pointer dereference `ki` appears to be potentially NULL. Output bogus values if it is. Caught by the static analyzer: > system/memory/lmkd/lmkd.cpp:2171:66: warning: Access to field 'kill_reason' results in a dereference of a null pointer (loaded from variable 'ki') [clang-analyzer-core.NullDereference] Bug: None Test: TreeHugger Change-Id: Iae26855528e1f7fec8f1455e06c7e813a732dc75 --- lmkd.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lmkd.cpp b/lmkd.cpp index 32ab26a..e377002 100644 --- a/lmkd.cpp +++ b/lmkd.cpp @@ -2168,8 +2168,8 @@ static int kill_one_process(struct proc* procp, int min_oom_score, struct kill_i mem_st = stats_read_memory_stat(per_app_memcg, pid, uid, rss_kb * 1024, swap_kb * 1024); - snprintf(desc, sizeof(desc), "lmk,%d,%d,%d,%d,%d", pid, (int)ki->kill_reason, procp->oomadj, - min_oom_score, ki->max_thrashing); + snprintf(desc, sizeof(desc), "lmk,%d,%d,%d,%d,%d", pid, ki ? (int)ki->kill_reason : -1, + procp->oomadj, min_oom_score, ki ? ki->max_thrashing : -1); trace_kill_start(pid, desc); /* CAP_KILL required */