From fe48901db0346659d4675632f82064991c103de7 Mon Sep 17 00:00:00 2001 From: Murilo Belluzzo Date: Tue, 2 Aug 2016 17:28:28 -0300 Subject: [PATCH] AP_ADC_ADS1115: Remove resource leak. Constructor allocate '_samples' but there was no destructor to deallocate it. Also, initializes '_gain' to silence CID 9144 although '_gain' wasn't being used uninitialized because of ::init(). CID 91424 --- libraries/AP_ADC/AP_ADC_ADS1115.cpp | 6 ++++++ libraries/AP_ADC/AP_ADC_ADS1115.h | 1 + 2 files changed, 7 insertions(+) diff --git a/libraries/AP_ADC/AP_ADC_ADS1115.cpp b/libraries/AP_ADC/AP_ADC_ADS1115.cpp index d7ecde8105..f89fc6971b 100644 --- a/libraries/AP_ADC/AP_ADC_ADS1115.cpp +++ b/libraries/AP_ADC/AP_ADC_ADS1115.cpp @@ -110,11 +110,17 @@ static const uint16_t mux_table[ADS1115_CHANNELS_COUNT] = { AP_ADC_ADS1115::AP_ADC_ADS1115() : _dev(hal.i2c_mgr->get_device(ADS1115_I2C_BUS, ADS1115_I2C_ADDR)) + , _gain(ADS1115_PGA_4P096) , _channel_to_read(0) { _samples = new adc_report_s[_channels_number]; } +AP_ADC_ADS1115::~AP_ADC_ADS1115() +{ + delete[] _samples; +} + bool AP_ADC_ADS1115::init() { hal.scheduler->suspend_timer_procs(); diff --git a/libraries/AP_ADC/AP_ADC_ADS1115.h b/libraries/AP_ADC/AP_ADC_ADS1115.h index bd67265e9b..6757258254 100644 --- a/libraries/AP_ADC/AP_ADC_ADS1115.h +++ b/libraries/AP_ADC/AP_ADC_ADS1115.h @@ -17,6 +17,7 @@ class AP_ADC_ADS1115 { public: AP_ADC_ADS1115(); + ~AP_ADC_ADS1115(); bool init(); size_t read(adc_report_s *report, size_t length) const;