From a5845e7b60cb8ef92be91f09150a732a33b130ab Mon Sep 17 00:00:00 2001 From: George Burgess IV Date: Thu, 5 Dec 2019 16:16:19 -0800 Subject: [PATCH] lmkd: fix an overallocation pidhash is defined as an array of pointers: static struct proc** pidhash = NULL; ...So we should be allocating `LINE_MAX * sizeof(struct proc *)` elems here. Given the current constants here, this saves ~130KB, so not a big deal, but still convenient. Caught by clang's static analyzer: system/memory/lmkd/statslog.c:354:19: warning: Result of 'calloc' is converted to a pointer of type 'struct proc *', which is incompatible with sizeof operand type 'struct proc' [clang-analyzer-unix.MallocSizeof] Bug: None Test: TreeHugger Change-Id: Iee9ca00a3a2a0ecababe9810d2ffcfc42169dd25 --- statslog.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/statslog.c b/statslog.c index c0fd6df..4f76261 100644 --- a/statslog.c +++ b/statslog.c @@ -351,7 +351,7 @@ bool init_poll_kernel(struct kernel_poll_info *poll_info) { static void proc_insert(struct proc* procp) { if (!pidhash) { - pidhash = calloc(PIDHASH_SZ, sizeof(struct proc)); + pidhash = calloc(PIDHASH_SZ, sizeof(*pidhash)); } int hval = pid_hashfn(procp->pid); @@ -426,7 +426,7 @@ void stats_purge_tasknames() { procp = next; } } - memset(pidhash, 0, PIDHASH_SZ * sizeof(struct proc)); + memset(pidhash, 0, PIDHASH_SZ * sizeof(*pidhash)); } #endif /* LMKD_LOG_STATS */