8000 Fix memory leak in compactCells by isaacbrodsky · Pull Request #685 · uber/h3 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix memory leak in compactCells #685

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

Merged
merged 4 commits into from
Sep 12, 2022
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
54 changes: 54 additions & 0 deletions src/apps/testapps/testCompactCells.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,60 @@ SUITE(compactCells) {
"compactCells returns E_RES_MISMATCH on bad input (parent error)");
}

TEST(compactCells_parentError2) {
// This test primarily ensures memory is not leaked upon invalid input,
// and ensures coverage of a very particular error branch in
// compactCells. The particular error code is not important.
const int numHex = 43;
H3Index bad[] = {0x2010202020202020,
0x2100000000,
0x7,
0x400000000,
0x20000000,
0x5000000000,
0x100321,
0x2100000000,
0x7,
0x400000000,
0x20000000,
0x2100000000,
0x7,
0x400000000,
0x20000000,
0x5000000000,
0x100321,
0x20000000,
0x5000000000,
0x100321,
0x2100000000,
0x7,
0x400000000,
0x5000000000,
0x100321,
0x2100000000,
0x7,
0x400000000,
0x20000000,
0x5000000000,
0x100321,
0x2100000000,
0x7,
0x400000000,
0x20000000,
0x5000000000,
0x100321,
0x20000000,
0x5000000000,
0x100321,
0x2100000000,
0x7,
0x400000000};
H3Index output[43] = {0};
t_assert(H3_EXPORT(compactCells)(bad, output, numHex) == E_RES_DOMAIN,
"compactCells returns E_RES_DOMAIN on bad input (parent "
"error #2)");
}

TEST(uncompactCells_wrongRes) {
int numHex = 3;
H3Index someHexagons[] = {0, 0, 0};
Expand Down
6 changes: 1 addition & 5 deletions src/h3lib/lib/h3Index.c
Original file line number Diff line number Diff line change
Expand Up @@ -446,16 +446,12 @@ H3Error H3_EXPORT(compactCells)(const H3Index *h3Set, H3Index *compactedSet,
H3Index parent;
H3Error parentError =
H3_EXPORT(cellToParent)(currIndex, parentRes, &parent);
// LCOV_EXCL_START
// Should never be reachable as a result of the compact
// algorithm.
if (parentError) {
// TODO: Determine if this is somehow reachable.
H3_MEMORY(free)(compactableHexes);
H3_MEMORY(free)(remainingHexes);
H3_MEMORY(free)(hashSetArray);
return parentError;
}
// LCOV_EXCL_STOP
// Modulus hash the parent into the temp array
// to determine if this index was included in
// the compactableHexes array
Expand Down
0