From 5c11bf9e4ff619b2c95a77d8448a639f2f712c1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Czern=C3=BD?= Date: Mon, 8 Mar 2021 18:00:39 +0100 Subject: [PATCH] M #-: Fix minor mem-leaks and valgring issues (#927) --- include/AddressRange.h | 10 +++++++++- include/IPAMRequest.h | 2 +- include/Request.h | 4 ++-- src/hm/HookPool.cc | 1 + src/host/HostShareNUMA.cc | 6 +++--- src/mad/MadManager.cc | 2 ++ src/pool/PoolSQL.cc | 4 +++- src/rm/RequestManagerAllocate.cc | 2 ++ src/rm/RequestManagerVirtualMachine.cc | 1 + src/vm/VirtualMachinePool.cc | 2 ++ src/vnm/AddressRange.cc | 2 +- 11 files changed, 27 insertions(+), 9 deletions(-) diff --git a/include/AddressRange.h b/include/AddressRange.h index d1862ebb17..96668076bb 100644 --- a/include/AddressRange.h +++ b/include/AddressRange.h @@ -418,7 +418,15 @@ protected: * Base constructor it cannot be called directly but from the * AddressRange factory constructor. */ - AddressRange(unsigned int _id):id(_id){}; + AddressRange(unsigned int _id) + : id(_id) + , size(0) + , ip(0) + , mac{} + , global6{} + , ula6{} + , ip6{} + {} /* ---------------------------------------------------------------------- */ /* Address/AR helper functions to build/parse driver messages */ diff --git a/include/IPAMRequest.h b/include/IPAMRequest.h index b6d9f8ebaf..8a930db526 100644 --- a/include/IPAMRequest.h +++ b/include/IPAMRequest.h @@ -190,7 +190,7 @@ private: int rc = response.parse_str_or_xml(*msg, error); - free(msg); + delete msg; return rc; } diff --git a/include/Request.h b/include/Request.h index 3e5938313f..3b328dcb96 100644 --- a/include/Request.h +++ b/include/Request.h @@ -296,8 +296,8 @@ protected: string method_name; // Configuration for authentication level of the API call - PoolObjectSQL::ObjectType auth_object; - AuthRequest::Operation auth_op; + PoolObjectSQL::ObjectType auth_object = PoolObjectSQL::ObjectType::NONE; + AuthRequest::Operation auth_op = AuthRequest::Operation::NONE; VMActions::Action vm_action; diff --git a/src/hm/HookPool.cc b/src/hm/HookPool.cc index c0c1c39543..9e1e56375b 100644 --- a/src/hm/HookPool.cc +++ b/src/hm/HookPool.cc @@ -58,6 +58,7 @@ error_name: error_str = oss.str(); error_common: + delete tmpl; oid = -1; return oid; diff --git a/src/host/HostShareNUMA.cc b/src/host/HostShareNUMA.cc index f23e9f4dd4..b82a350111 100644 --- a/src/host/HostShareNUMA.cc +++ b/src/host/HostShareNUMA.cc @@ -801,10 +801,10 @@ void HostShareNUMA::set_monitorization(Template &ht, unsigned int _vt) for (auto it = pages.begin(); it != pages.end(); ++it) { - unsigned int pages; - unsigned int free; + unsigned int pages = 0; + unsigned int free = 0; - unsigned long size; + unsigned long size = 0; if ( (*it)->vector_value("NODE_ID", node_id) == -1 ) { diff --git a/src/mad/MadManager.cc b/src/mad/MadManager.cc index b39682f1cb..48559d80c7 100644 --- a/src/mad/MadManager.cc +++ b/src/mad/MadManager.cc @@ -138,6 +138,8 @@ void MadManager::stop() delete mads[i]; } + mads.clear(); + unlock(); } diff --git a/src/pool/PoolSQL.cc b/src/pool/PoolSQL.cc index 7377f68052..80321e14be 100644 --- a/src/pool/PoolSQL.cc +++ b/src/pool/PoolSQL.cc @@ -127,6 +127,8 @@ int PoolSQL::allocate(PoolObjectSQL *objsql, string& error_str) { unlock(); + delete objsql; + return -1; } @@ -274,7 +276,7 @@ PoolObjectSQL * PoolSQL::get_ro(const string& name, int uid) /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -int PoolSQL::dump(string& oss, const string& elem_name, const string& column, +int PoolSQL::dump(string& oss, const string& elem_name, const string& column, const char* table, const string& where, int sid, int eid, bool desc) { ostringstream cmd; diff --git a/src/rm/RequestManagerAllocate.cc b/src/rm/RequestManagerAllocate.cc index ec44947303..32f2afe5f7 100644 --- a/src/rm/RequestManagerAllocate.cc +++ b/src/rm/RequestManagerAllocate.cc @@ -1386,6 +1386,8 @@ Request::ErrorCode HookAllocate::pool_allocate( oss << "Invalid Hook type: " << hk_type; att.resp_msg = oss.str(); + delete tmpl; + return Request::INTERNAL; } diff --git a/src/rm/RequestManagerVirtualMachine.cc b/src/rm/RequestManagerVirtualMachine.cc index 723833ec8b..9d89da298a 100644 --- a/src/rm/RequestManagerVirtualMachine.cc +++ b/src/rm/RequestManagerVirtualMachine.cc @@ -529,6 +529,7 @@ void VirtualMachineAction::request_execute(xmlrpc_c::paramList const& paramList, if (vm_authorization(id, 0, 0, att, 0, 0, 0) == false) { + vm->unlock(); return; } diff --git a/src/vm/VirtualMachinePool.cc b/src/vm/VirtualMachinePool.cc index 66cd5f9bc0..d7364ad909 100644 --- a/src/vm/VirtualMachinePool.cc +++ b/src/vm/VirtualMachinePool.cc @@ -1131,6 +1131,8 @@ void VirtualMachinePool::delete_attach_nic(int vid) tmpl.set(nic->vector_attribute()); + delete nic; + Quotas::quota_del(Quotas::NETWORK, uid, gid, &tmpl); } diff --git a/src/vnm/AddressRange.cc b/src/vnm/AddressRange.cc index 7c49066dbd..c0b28126e9 100644 --- a/src/vnm/AddressRange.cc +++ b/src/vnm/AddressRange.cc @@ -1520,7 +1520,7 @@ int AddressRange::free_addr(PoolObjectSQL::ObjectType ot, int obid, const string& mac_s) { string error_msg; - unsigned int mac_i[2]; + unsigned int mac_i[2] = {}; mac_to_i(mac_s, mac_i);