Skip to content

Commit

Permalink
fix position_estimator_inav_main: put terrain_estimator on the stack
Browse files Browse the repository at this point in the history
This fixes a memory leak
  • Loading branch information
bkueng committed May 3, 2016
1 parent 44a0981 commit 27d821a
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ int position_estimator_inav_thread_main(int argc, char *argv[])

/* wait for initial baro value */
bool wait_baro = true;
TerrainEstimator *terrain_estimator = new TerrainEstimator();
TerrainEstimator terrain_estimator;

thread_running = true;
hrt_abstime baro_wait_for_sample_time = hrt_absolute_time();
Expand Down Expand Up @@ -1264,8 +1264,8 @@ int position_estimator_inav_thread_main(int argc, char *argv[])
}

/* run terrain estimator */
terrain_estimator->predict(dt, &att, &sensor, &lidar);
terrain_estimator->measurement_update(hrt_absolute_time(), &gps, &lidar, &att);
terrain_estimator.predict(dt, &att, &sensor, &lidar);
terrain_estimator.measurement_update(hrt_absolute_time(), &gps, &lidar, &att);

if (inav_verbose_mode) {
/* print updates rate */
Expand Down Expand Up @@ -1358,8 +1358,8 @@ int position_estimator_inav_thread_main(int argc, char *argv[])
global_pos.eph = eph;
global_pos.epv = epv;

if (terrain_estimator->is_valid()) {
global_pos.terrain_alt = global_pos.alt - terrain_estimator->get_distance_to_ground();
if (terrain_estimator.is_valid()) {
global_pos.terrain_alt = global_pos.alt - terrain_estimator.get_distance_to_ground();
global_pos.terrain_alt_valid = true;

} else {
Expand Down

0 comments on commit 27d821a

Please sign in to comment.