Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove null checks before free. Reverses commit eb5395b #643

Merged
merged 5 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,21 @@ int main(){
}
```

By default we use:
```C
static roaring_memory_t global_memory_hook = {
.malloc = malloc,
.realloc = realloc,
.calloc = calloc,
.free = free,
.aligned_malloc = roaring_bitmap_aligned_malloc,
.aligned_free = roaring_bitmap_aligned_free,
};
```

We require that the `free`/`aligned_free` functions follow the C
convention where `free(NULL)`/`aligned_free(NULL)` have no effect.


# Example (C)

Expand Down
12 changes: 3 additions & 9 deletions src/containers/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,8 @@ int array_container_shrink_to_fit(array_container_t *src) {

/* Free memory. */
void array_container_free(array_container_t *arr) {
if (arr->array !=
NULL) { // Jon Strabala reports that some tools complain otherwise
roaring_free(arr->array);
arr->array = NULL; // pedantic
}
if (arr == NULL) return;
roaring_free(arr->array);
lemire marked this conversation as resolved.
Show resolved Hide resolved
roaring_free(arr);
}

Expand Down Expand Up @@ -177,10 +174,7 @@ void array_container_grow(array_container_t *container, int32_t min,
(uint16_t *)roaring_realloc(array, new_capacity * sizeof(uint16_t));
if (container->array == NULL) roaring_free(array);
} else {
// Jon Strabala reports that some tools complain otherwise
if (array != NULL) {
roaring_free(array);
}
roaring_free(array);
container->array =
(uint16_t *)roaring_malloc(new_capacity * sizeof(uint16_t));
}
Expand Down
7 changes: 2 additions & 5 deletions src/containers/bitset.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,8 @@ void bitset_container_add_from_range(bitset_container_t *bitset, uint32_t min,

/* Free memory. */
void bitset_container_free(bitset_container_t *bitset) {
if (bitset->words !=
NULL) { // Jon Strabala reports that some tools complain otherwise
roaring_aligned_free(bitset->words);
bitset->words = NULL; // pedantic
}
if (bitset == NULL) return;
roaring_aligned_free(bitset->words);
lemire marked this conversation as resolved.
Show resolved Hide resolved
roaring_free(bitset);
}

Expand Down
12 changes: 3 additions & 9 deletions src/containers/run.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,8 @@ void run_container_offset(const run_container_t *c, container_t **loc,

/* Free memory. */
void run_container_free(run_container_t *run) {
if (run->runs !=
NULL) { // Jon Strabala reports that some tools complain otherwise
roaring_free(run->runs);
run->runs = NULL; // pedantic
}
if (run == NULL) return;
roaring_free(run->runs);
lemire marked this conversation as resolved.
Show resolved Hide resolved
roaring_free(run);
}

Expand All @@ -211,10 +208,7 @@ void run_container_grow(run_container_t *run, int32_t min, bool copy) {
run->capacity * sizeof(rle16_t));
if (run->runs == NULL) roaring_free(oldruns);
} else {
// Jon Strabala reports that some tools complain otherwise
if (run->runs != NULL) {
roaring_free(run->runs);
}
roaring_free(run->runs);
run->runs = (rle16_t *)roaring_malloc(run->capacity * sizeof(rle16_t));
}
// We may have run->runs == NULL.
Expand Down
Loading