Fix memory leaks
authorRomain Forlot <romain.forlot@iot.bzh>
Tue, 23 May 2017 22:46:43 +0000 (00:46 +0200)
committerRomain Forlot <romain.forlot@iot.bzh>
Tue, 23 May 2017 22:46:43 +0000 (00:46 +0200)
Change-Id: I4a33b6d5f1f3b73af113aff62b024329b0ed5288
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
CAN-binder/low-can-binding/binding/low-can-cb.cpp
CAN-binder/low-can-binding/diagnostic/active-diagnostic-request.cpp
CAN-binder/low-can-binding/diagnostic/active-diagnostic-request.hpp
CAN-binder/low-can-binding/diagnostic/diagnostic-manager.cpp

index 9e85f5c..0dcff1d 100644 (file)
@@ -50,6 +50,8 @@ void on_no_clients(std::string message)
                if( adr != nullptr)
                        configuration_t::instance().get_diagnostic_manager().cleanup_request(adr, true);
        }
+       delete diag_req;
+       diag_req = nullptr;
 }
 
 static void push_n_notify(const can_message_t& cm)
@@ -207,6 +209,8 @@ static int subscribe_unsubscribe_signals(struct afb_req request, bool subscribe,
                        diag_m.cleanup_request(
                                diag_m.find_recurring_request(diag_req), true);
                        WARNING(binder_interface, "%s: signal: %s isn't supported. Canceling operation.", __FUNCTION__, sig->get_name().c_str());
+                       delete diag_req;
+                       diag_req = nullptr;
                        return -1;
                }
 
index e9f0cd1..35a6c56 100644 (file)
@@ -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_;
index c295bed..a1b8ab5 100644 (file)
@@ -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();
index 4f4b842..49013f8 100644 (file)
@@ -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