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
diff --git a/lmkd.cpp b/lmkd.cpp
index 32ab26a..e377002 100644
--- a/lmkd.cpp
+++ b/lmkd.cpp
@@ -2168,8 +2168,8 @@
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 */