Page MenuHomeWildfire Games

#5288: N18 - realloc() possible leak
AbandonedPublic

Authored by animus on Jan 20 2024, 11:39 AM.

Details

Reviewers
None
Trac Tickets
#5288
Summary

"realloc() possible leak: when realloc() fails in allocating memory, original pointer 'dsd->entries' is lost. Consider assigning realloc() to a temporary pointer. mongoose.cpp" -PVS Studio

Do note that there is a TODO within the code (TODO(lsm): propagate an error to the caller).
I'd love to solve that too if someone could point me in the right direction (what mechanism is generally used? is there another function which i can use as an example?)

Test Plan

Cxx tests passed.
compiles and runs.

Diff Detail

Lint
Lint Skipped
Unit
Unit Tests Skipped

Event Timeline

animus requested review of this revision.Jan 20 2024, 11:39 AM
animus created this revision.

We're trying to avoid patching third parties. Ideally a PR should be created in the third party repo and then our library might be updated.

phosit added a subscriber: phosit.Jan 20 2024, 1:42 PM

We're trying to avoid patching third parties. Ideally a PR should be created in the third party repo and then our library might be updated.

IIRC We don't update mongoose due to the licence change.

If the dsd->entries == NULL || dsd->num_entries >= dsd->arr_size branch isn't taken, dsd->num_entries shouldn't be set to 0.
I think you ment to set dsd->entries to reallocated_memory. Instead of calling realloc again.

Setting just the dsd->num_entries to 0 is wrong. The dsd->entries[i].file_name won't be freed.

animus abandoned this revision.Jan 27 2024, 1:35 PM

We're trying to avoid patching third parties. Ideally a PR should be created in the third party repo and then our library might be updated.

That makes sense.