Skip to content

Commit

Permalink
Handle potential calloc failures in dictionary_new. In such case free…
Browse files Browse the repository at this point in the history
… all allocated resources and return NULL
  • Loading branch information
AigarsG authored and lmoellendorf committed Mar 17, 2024
1 parent 432fe69 commit 6fc4ec0
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/dictionary.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,13 @@ dictionary * dictionary_new(size_t size)
d->val = (char**) calloc(size, sizeof *d->val);
d->key = (char**) calloc(size, sizeof *d->key);
d->hash = (unsigned*) calloc(size, sizeof *d->hash);
if (!d->size || !d->val || !d->hash) {
free((void *) d->size);
free((void *) d->val);
free((void *) d->hash);
free(d);
d = NULL;
}
}
return d ;
}
Expand Down

0 comments on commit 6fc4ec0

Please sign in to comment.