From 5b2b27e32161c9bc3904d54fd58b4770067d0d2b Mon Sep 17 00:00:00 2001 From: Cheyenne Wills Date: Thu, 1 Jul 2021 15:59:40 -0600 Subject: [PATCH] opr: Check for failed memory allocation Several static analysis tools have identified various problems: - missing checks to ensure *alloc was successful (infer) To resolve the above problems: - add checks to ensure *alloc was successful before using the memory This commit is a reorganization of commits developed by Pat Riehecky, who ran the static analysis tools and developed the fixes. Change-Id: I9396b8327f8283c60821050c75de1c36e0ebd12e Reviewed-on: https://gerrit.openafs.org/14684 Tested-by: BuildBot Reviewed-by: Cheyenne Wills Reviewed-by: Michael Meffie --- src/opr/dict.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/opr/dict.c b/src/opr/dict.c index bd6f68ef88..11065d713e 100644 --- a/src/opr/dict.c +++ b/src/opr/dict.c @@ -44,9 +44,18 @@ opr_dict_Init(unsigned int size) return NULL; dict = calloc(1, sizeof(struct opr_dict)); + if (dict == NULL) { + return NULL; + } + dict->size = size; dict->table = malloc(dict->size * sizeof(struct opr_queue)); + if (dict->table == NULL) { + free(dict); + return NULL; + } + for (i = 0; i < dict->size; i++) { opr_queue_Init(&dict->table[i]); }