From ed81d57a5cade4adf969d0a4dde9cab9b83512d6 Mon Sep 17 00:00:00 2001 From: Cheyenne Wills Date: Thu, 1 Jul 2021 15:33:43 -0600 Subject: [PATCH] butc: Fix problems found by static analysis Several static analysis tools have identified various problems: - use of uninitlized variables (scan-build) - missing checks to ensure *alloc was successful (infer) - possible memory leaks (scan-build, cppcheck) To resolve the above problems: - ensure variables are initialized to safe defaults - add checks to ensure *alloc was successful before using the memory - fix possible memory leaks by freeing memory This commit is a reorganization of commits developed by Pat Riehecky, who ran the static analysis tools and developed the fixes. Change-Id: Ic5e222e344df4d5a3e317fcbb2f30a09dce93793 Reviewed-on: https://gerrit.openafs.org/14679 Tested-by: BuildBot Reviewed-by: Michael Meffie --- src/butc/list.c | 2 ++ src/butc/recoverDb.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/butc/list.c b/src/butc/list.c index fac79aeb24..2707677084 100644 --- a/src/butc/list.c +++ b/src/butc/list.c @@ -9,6 +9,7 @@ #include #include +#include #include @@ -61,6 +62,7 @@ CreateNode(struct dumpNode **newNode) { /* get space */ *newNode = calloc(1, sizeof(struct dumpNode)); + opr_Assert(*newNode != NULL); (*newNode)->next = dumpQHeader->next; dumpQHeader->next = *newNode; diff --git a/src/butc/recoverDb.c b/src/butc/recoverDb.c index 36abc56166..33efc32875 100644 --- a/src/butc/recoverDb.c +++ b/src/butc/recoverDb.c @@ -163,7 +163,7 @@ scanVolData(afs_int32 taskId, struct butm_tapeInfo *curTapePtr, char *buffer[2]; int hasdata[2], curr, prev; afs_uint32 chunkSize = 0; - afs_int32 nbytes; + afs_int32 nbytes = 0; afs_int32 code = 0; afs_int32 rcode, tcode;