From cc1b76682443f6de28cd07180a39ba8a6d0edb5d Mon Sep 17 00:00:00 2001 From: Peter Duerr Date: Mon, 7 Aug 2017 15:35:21 +0200 Subject: [PATCH] Fix memory leaks identified by cppcheck * Add `free` / `delete` * Add comment explaining the (presumed) motivation for the use of new instead of allocating on the stack --- src/modules/ekf2_replay/ekf2_replay_main.cpp | 2 ++ src/modules/uORB/uORB_tests/uORBTest_UnitTest.cpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/modules/ekf2_replay/ekf2_replay_main.cpp b/src/modules/ekf2_replay/ekf2_replay_main.cpp index 68a372faa5..86db74f5cc 100644 --- a/src/modules/ekf2_replay/ekf2_replay_main.cpp +++ b/src/modules/ekf2_replay/ekf2_replay_main.cpp @@ -1049,6 +1049,8 @@ void Ekf2Replay::task_main() PX4_INFO("TAS innov RMS = %6.3f", (double)sqrtf(_tasInnovSumSq / _numInnovSamples)); } + free(path_to_replay_log); + } void Ekf2Replay::task_main_trampoline(int argc, char *argv[]) diff --git a/src/modules/uORB/uORB_tests/uORBTest_UnitTest.cpp b/src/modules/uORB/uORB_tests/uORBTest_UnitTest.cpp index e6860d0c9e..26666a07f3 100644 --- a/src/modules/uORB/uORB_tests/uORBTest_UnitTest.cpp +++ b/src/modules/uORB/uORB_tests/uORBTest_UnitTest.cpp @@ -89,6 +89,7 @@ int uORBTest::UnitTest::pubsublatency_main() const unsigned maxruns = 1000; unsigned timingsgroup = 0; + // timings has to be on the heap to keep frame size below 2048 bytes unsigned *timings = new unsigned[maxruns]; for (unsigned i = 0; i < maxruns; i++) { @@ -129,6 +130,7 @@ int uORBTest::UnitTest::pubsublatency_main() if (f == nullptr) { warnx("Error opening file!\n"); + delete[] timings; return uORB::ERROR; }