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 <buildbot@rampaginggeek.com>
Reviewed-by: Cheyenne Wills <cwills@sinenomine.net>
Reviewed-by: Michael Meffie <mmeffie@sinenomine.net>
This commit is contained in:
Cheyenne Wills 2021-07-01 15:59:40 -06:00 committed by Michael Meffie
parent c20dceb392
commit 5b2b27e321

View File

@ -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]);
}