Skip to content

Commit

Permalink
fix memory leak in removeDuplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryan committed Jan 27, 2023
1 parent a734108 commit 3f361e7
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions apriltag_ros/src/common_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,22 +419,23 @@ void TagDetector::removeDuplicates ()
// The entire detection set was parsed
return;
}
apriltag_detection_t *detection;
zarray_get(detections_, count, &detection);
int id_current = detection->id;
apriltag_detection_t *next_detection, *current_detection;
zarray_get(detections_, count, &current_detection);
int id_current = current_detection->id;
// Default id_next value of -1 ensures that if the last detection
// is a duplicated tag ID, it will get removed
int id_next = -1;
if (count < zarray_size(detections_)-1)
{
zarray_get(detections_, count+1, &detection);
id_next = detection->id;
zarray_get(detections_, count+1, &next_detection);
id_next = next_detection->id;
}
if (id_current == id_next || (id_current != id_next && duplicate_detected))
{
duplicate_detected = true;
// Remove the current tag detection from detections array
int shuffle = 0;
apriltag_detection_destroy(current_detection);
zarray_remove_index(detections_, count, shuffle);
if (id_current != id_next)
{
Expand Down

0 comments on commit 3f361e7

Please sign in to comment.