[fix] calloc instead of malloc when performing initialization on structs that may fail halfway and need to clean up while partially initialized (calloc will set all the bytes to zero so the member pointers are NULL instead of garbage memory)
This commit is contained in:
@@ -56,7 +56,7 @@ int bloom_filter_add(bloom_filter_t *self, const char *key, size_t len) {
|
||||
}
|
||||
|
||||
bloom_filter_t *bloom_filter_new(uint64_t capacity, double error) {
|
||||
bloom_filter_t *bloom = malloc(sizeof(bloom_filter_t));
|
||||
bloom_filter_t *bloom = calloc(1, sizeof(bloom_filter_t));
|
||||
|
||||
if (bloom == NULL) {
|
||||
return NULL;
|
||||
@@ -220,4 +220,4 @@ void bloom_filter_destroy(bloom_filter_t *self) {
|
||||
}
|
||||
|
||||
free(self);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user