Skip to content

Commit

Permalink
Fix memory leaks to appease asan when running on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
grahamboree committed Dec 31, 2023
1 parent 6adbce4 commit 6c8862c
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions Tests/Recast/Tests_RecastFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ TEST_CASE("rcFilterLowHangingWalkableObstacles", "[recast, filtering]")
rcFilterLowHangingWalkableObstacles(&context, walkableHeight, heightfield);

REQUIRE(heightfield.spans[0]->area == 1);

rcFree(span);
}

SECTION("Span with span above that is higher than walkableHeight is unchanged")
Expand Down Expand Up @@ -72,6 +74,9 @@ TEST_CASE("rcFilterLowHangingWalkableObstacles", "[recast, filtering]")
// Check that nothing has changed.
REQUIRE(heightfield.spans[0]->area == 1);
REQUIRE(heightfield.spans[0]->next->area == 1);

rcFree(span);
rcFree(secondSpan);
}

SECTION("Marks low obstacles walkable if they're below the walkableClimb")
Expand All @@ -96,6 +101,9 @@ TEST_CASE("rcFilterLowHangingWalkableObstacles", "[recast, filtering]")
// Check that the second span was changed to walkable.
REQUIRE(heightfield.spans[0]->area == 1);
REQUIRE(heightfield.spans[0]->next->area == 1);

rcFree(span);
rcFree(secondSpan);
}

SECTION("Low obstacle that overlaps the walkableClimb distance is not changed")
Expand All @@ -120,6 +128,9 @@ TEST_CASE("rcFilterLowHangingWalkableObstacles", "[recast, filtering]")
// Check that the second span was changed to walkable.
REQUIRE(heightfield.spans[0]->area == 1);
REQUIRE(heightfield.spans[0]->next->area == RC_NULL_AREA);

rcFree(span);
rcFree(secondSpan);
}

SECTION("Only the first of multiple, low obstacles are marked walkable")
Expand Down Expand Up @@ -153,6 +164,12 @@ TEST_CASE("rcFilterLowHangingWalkableObstacles", "[recast, filtering]")
REQUIRE(currentSpan->area == (i <= 1 ? 1 : RC_NULL_AREA));
currentSpan = currentSpan->next;
}

while (span != NULL)
{
rcFree(span);
span = span->next;
}
}
}

Expand Down Expand Up @@ -216,6 +233,15 @@ TEST_CASE("rcFilterLedgeSpans", "[recast, filtering]")
REQUIRE(span->smax == 1);
}
}

// Free all the heightfield spans
for (int x = 0; x < heightfield.width; ++x)
{
for (int z = 0; z < heightfield.height; ++z)
{
rcFree(heightfield.spans[x + z * heightfield.width]);
}
}
}

SECTION("Edge spans are marked unwalkable")
Expand Down Expand Up @@ -257,6 +283,15 @@ TEST_CASE("rcFilterLedgeSpans", "[recast, filtering]")
REQUIRE(span->smax == 1);
}
}

// Free all the heightfield spans
for (int x = 0; x < heightfield.width; ++x)
{
for (int z = 0; z < heightfield.height; ++z)
{
rcFree(heightfield.spans[x + z * heightfield.width]);
}
}
}
}

Expand Down Expand Up @@ -292,6 +327,8 @@ TEST_CASE("rcFilterWalkableLowHeightSpans", "[recast, filtering]")
rcFilterWalkableLowHeightSpans(&context, walkableHeight, heightfield);

REQUIRE(heightfield.spans[0]->area == 1);

rcFree(span);
}

SECTION("span with lots of room above is unchanged")
Expand All @@ -313,6 +350,9 @@ TEST_CASE("rcFilterWalkableLowHeightSpans", "[recast, filtering]")

REQUIRE(heightfield.spans[0]->area == 1);
REQUIRE(heightfield.spans[0]->next->area == RC_NULL_AREA);

rcFree(overheadSpan);
rcFree(span);
}

SECTION("Span with low hanging obstacle is marked as unwalkable")
Expand All @@ -334,5 +374,10 @@ TEST_CASE("rcFilterWalkableLowHeightSpans", "[recast, filtering]")

REQUIRE(heightfield.spans[0]->area == RC_NULL_AREA);
REQUIRE(heightfield.spans[0]->next->area == RC_NULL_AREA);

rcFree(overheadSpan);
rcFree(span);
}

rcFree(heightfield.spans);
}

0 comments on commit 6c8862c

Please sign in to comment.