From ab4d52b65359c571267c71244578321580520c20 Mon Sep 17 00:00:00 2001 From: Romain Forlot Date: Wed, 24 May 2017 00:46:43 +0200 Subject: Fix memory leaks Change-Id: I4a33b6d5f1f3b73af113aff62b024329b0ed5288 Signed-off-by: Romain Forlot --- .../low-can-binding/diagnostic/active-diagnostic-request.cpp | 7 +++++++ .../low-can-binding/diagnostic/active-diagnostic-request.hpp | 1 + CAN-binder/low-can-binding/diagnostic/diagnostic-manager.cpp | 2 ++ 3 files changed, 10 insertions(+) (limited to 'CAN-binder/low-can-binding/diagnostic') diff --git a/CAN-binder/low-can-binding/diagnostic/active-diagnostic-request.cpp b/CAN-binder/low-can-binding/diagnostic/active-diagnostic-request.cpp index e9f0cd1..35a6c56 100644 --- a/CAN-binder/low-can-binding/diagnostic/active-diagnostic-request.cpp +++ b/CAN-binder/low-can-binding/diagnostic/active-diagnostic-request.cpp @@ -82,6 +82,13 @@ active_diagnostic_request_t::active_diagnostic_request_t(const std::string& bus, timeout_clock_{frequency_clock_t(10)} {} +active_diagnostic_request_t::~active_diagnostic_request_t() +{ + socket_.close(); + delete handle_; + handle_ = nullptr; +} + uint32_t active_diagnostic_request_t::get_id() const { return id_; diff --git a/CAN-binder/low-can-binding/diagnostic/active-diagnostic-request.hpp b/CAN-binder/low-can-binding/diagnostic/active-diagnostic-request.hpp index c295bed..a1b8ab5 100644 --- a/CAN-binder/low-can-binding/diagnostic/active-diagnostic-request.hpp +++ b/CAN-binder/low-can-binding/diagnostic/active-diagnostic-request.hpp @@ -95,6 +95,7 @@ public: const std::string& name, bool wait_for_multiple_responses, const DiagnosticResponseDecoder decoder, const DiagnosticResponseCallback callback, float frequencyHz); + ~active_diagnostic_request_t(); uint32_t get_id() const; DiagnosticRequestHandle* get_handle(); diff --git a/CAN-binder/low-can-binding/diagnostic/diagnostic-manager.cpp b/CAN-binder/low-can-binding/diagnostic/diagnostic-manager.cpp index 4f4b842..49013f8 100644 --- a/CAN-binder/low-can-binding/diagnostic/diagnostic-manager.cpp +++ b/CAN-binder/low-can-binding/diagnostic/diagnostic-manager.cpp @@ -232,6 +232,8 @@ void diagnostic_manager_t::find_and_erase(active_diagnostic_request_t* entry, st void diagnostic_manager_t::cancel_request(active_diagnostic_request_t* entry) { entry->get_socket().close(); + delete entry; + entry = nullptr; } /// @brief Cleanup a specific request if it isn't running and get complete. As it is almost -- cgit 1.2.3-korg