Skip to content

Commit 6fc4ec0

Browse files
AigarsGlmoellendorf
authored andcommitted
Handle potential calloc failures in dictionary_new. In such case free all allocated resources and return NULL
1 parent 432fe69 commit 6fc4ec0

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/dictionary.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,13 @@ dictionary * dictionary_new(size_t size)
154154
d->val = (char**) calloc(size, sizeof *d->val);
155155
d->key = (char**) calloc(size, sizeof *d->key);
156156
d->hash = (unsigned*) calloc(size, sizeof *d->hash);
157+
if (!d->size || !d->val || !d->hash) {
158+
free((void *) d->size);
159+
free((void *) d->val);
160+
free((void *) d->hash);
161+
free(d);
162+
d = NULL;
163+
}
157164
}
158165
return d ;
159166
}

0 commit comments

Comments
 (0)