From 63b08b596207b230255d409b2483bcc50fc2e584 Mon Sep 17 00:00:00 2001 From: Vivek Date: Mon, 7 Aug 2023 09:43:41 -0700 Subject: [PATCH] [ASAN] Fix Indirect Mem Leaks in Orchagent (#2869) **What I did** Fix the Mem Leak by moving the raw pointers in type_maps to use smart pointers **Why I did it** ``` Indirect leak of 83776 byte(s) in 476 object(s) allocated from: #0 0x7f0a2a414647 in operator new(unsigned long) ../../../../src/libsanitizer/asan/asan_new_delete.cpp:99 #1 0x5555590cc923 in __gnu_cxx::new_allocator, std::allocator > const, referenced_object> > >::allocate(unsigned long, void const*) /usr/include/c++/10/ext/new_allocator.h:115 #2 0x5555590cc923 in std::allocator_traits, std::allocator > const, referenced_object> > > >::allocate(std::allocator, std::allocator > const, referenced_object> > >&, unsigned long) /usr/include/c++/10/bits/alloc_traits.h:460 #3 0x5555590cc923 in std::_Rb_tree, std::allocator >, std::pair, std::allocator > const, referenced_object>, std::_Select1st, std::allocator > const, referenced_object> >, std::less, std::allocator > >, std::allocator, std::allocator > const, referenced_object> > >::_M_get_node() /usr/include/c++/10/bits/stl_tree.h:584 #4 0x5555590cc923 in std::_Rb_tree_node, std::allocator > const, referenced_object> >* std::_Rb_tree, std::allocator >, std::pair, std::allocator > const, referenced_object>, std::_Select1st, std::allocator > const, referenced_object> >, std::less, std::allocator > >, std::allocator, std::allocator > const, referenced_object> > >::_M_create_node, std::allocator > const&>, std::tuple<> >(std::piecewise_construct_t const&, std::tuple, std::allocator > const&>&&, std::tuple<>&&) /usr/include/c++/10/bits/stl_tree.h:634 #5 0x5555590cc923 in std::_Rb_tree_iterator, std::allocator > const, referenced_object> > std::_Rb_tree, std::allocator >, std::pair, std::allocator > const, referenced_object>, std::_Select1st, std::allocator > const, referenced_object> >, std::less, std::allocator > >, std::allocator, std::allocator > const, referenced_object> > >::_M_emplace_hint_unique, std::allocator > const&>, std::tuple<> >(std::_Rb_tree_const_iterator, std::allocator > const, referenced_object> >, std::piecewise_construct_t const&, std::tuple, std::allocator > const&>&&, std::tuple<>&&) /usr/include/c++/10/bits/stl_tree.h:2461 #6 0x5555590e8757 in std::map, std::allocator >, referenced_object, std::less, std::allocator > >, std::allocator, std::allocator > const, referenced_object> > >::operator[](std::__cxx11::basic_string, std::allocator > const&) /usr/include/c++/10/bits/stl_map.h:501 #7 0x5555590d48b0 in Orch::setObjectReference(std::map, std::allocator >, std::map, std::allocator >, referenced_object, std::less, std::allocator > >, std::allocator, std::allocator > const, referenced_object> > >*, std::less, std::allocator > >, std::allocator, std::allocator > const, std::map, std::allocator >, referenced_object, std::less, std::allocator > >, std::allocator, std::allocator > const, referenced_object> > >*> > >&, std::__cxx11::basic_string, std::allocator > const&, std::__cxx11::basic_string, std::allocator > const&, std::__cxx11::basic_string, std::allocator > const&, std::__cxx11::basic_string, std::allocator > const&) orchagent/orch.cpp:450 #8 0x5555594ff66b in QosOrch::handleQueueTable(Consumer&, std::tuple, std::allocator >, std::__cxx11::basic_string, std::allocator >, std::vector, std::allocator >, std::__cxx11::basic_string, std::allocator > >, std::allocator, std::allocator >, std::__cxx11::basic_string, std::allocator > > > > >&) orchagent/qosorch.cpp:1763 #9 0x5555594edbd6 in QosOrch::doTask(Consumer&) orchagent/qosorch.cpp:2179 #10 0x5555590c8743 in Consumer::drain() orchagent/orch.cpp:241 #11 0x5555590c8743 in Consumer::drain() orchagent/orch.cpp:238 #12 0x5555590c8743 in Consumer::execute() orchagent/orch.cpp:235 #13 0x555559090dad in OrchDaemon::start() orchagent/orchdaemon.cpp:755 #14 0x555558e9be25 in main orchagent/main.cpp:766 #15 0x7f0a299b6d09 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x23d09) ``` --- orchagent/bufferorch.cpp | 12 ++++++------ orchagent/orch.h | 2 +- orchagent/qosorch.cpp | 32 ++++++++++++++++---------------- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/orchagent/bufferorch.cpp b/orchagent/bufferorch.cpp index f1f3216b54..e6250f5203 100644 --- a/orchagent/bufferorch.cpp +++ b/orchagent/bufferorch.cpp @@ -30,12 +30,12 @@ static const vector bufferPoolWatermarkStatIds = }; type_map BufferOrch::m_buffer_type_maps = { - {APP_BUFFER_POOL_TABLE_NAME, new object_reference_map()}, - {APP_BUFFER_PROFILE_TABLE_NAME, new object_reference_map()}, - {APP_BUFFER_QUEUE_TABLE_NAME, new object_reference_map()}, - {APP_BUFFER_PG_TABLE_NAME, new object_reference_map()}, - {APP_BUFFER_PORT_INGRESS_PROFILE_LIST_NAME, new object_reference_map()}, - {APP_BUFFER_PORT_EGRESS_PROFILE_LIST_NAME, new object_reference_map()} + {APP_BUFFER_POOL_TABLE_NAME, make_shared()}, + {APP_BUFFER_PROFILE_TABLE_NAME, make_shared()}, + {APP_BUFFER_QUEUE_TABLE_NAME, make_shared()}, + {APP_BUFFER_PG_TABLE_NAME, make_shared()}, + {APP_BUFFER_PORT_INGRESS_PROFILE_LIST_NAME, make_shared()}, + {APP_BUFFER_PORT_EGRESS_PROFILE_LIST_NAME, make_shared()} }; map buffer_to_ref_table_map = { diff --git a/orchagent/orch.h b/orchagent/orch.h index 1d5bbc4672..8ef86e530f 100644 --- a/orchagent/orch.h +++ b/orchagent/orch.h @@ -71,7 +71,7 @@ typedef struct } referenced_object; typedef std::map object_reference_map; -typedef std::map type_map; +typedef std::map> type_map; typedef std::map object_map; typedef std::pair object_map_pair; diff --git a/orchagent/qosorch.cpp b/orchagent/qosorch.cpp index c61885992e..233cb894c5 100644 --- a/orchagent/qosorch.cpp +++ b/orchagent/qosorch.cpp @@ -74,22 +74,22 @@ map scheduler_meter_map = { }; type_map QosOrch::m_qos_maps = { - {CFG_DSCP_TO_TC_MAP_TABLE_NAME, new object_reference_map()}, - {CFG_MPLS_TC_TO_TC_MAP_TABLE_NAME, new object_reference_map()}, - {CFG_DOT1P_TO_TC_MAP_TABLE_NAME, new object_reference_map()}, - {CFG_TC_TO_QUEUE_MAP_TABLE_NAME, new object_reference_map()}, - {CFG_SCHEDULER_TABLE_NAME, new object_reference_map()}, - {CFG_WRED_PROFILE_TABLE_NAME, new object_reference_map()}, - {CFG_PORT_QOS_MAP_TABLE_NAME, new object_reference_map()}, - {CFG_QUEUE_TABLE_NAME, new object_reference_map()}, - {CFG_TC_TO_PRIORITY_GROUP_MAP_TABLE_NAME, new object_reference_map()}, - {CFG_PFC_PRIORITY_TO_PRIORITY_GROUP_MAP_TABLE_NAME, new object_reference_map()}, - {CFG_PFC_PRIORITY_TO_QUEUE_MAP_TABLE_NAME, new object_reference_map()}, - {CFG_DSCP_TO_FC_MAP_TABLE_NAME, new object_reference_map()}, - {CFG_EXP_TO_FC_MAP_TABLE_NAME, new object_reference_map()}, - {CFG_TC_TO_DOT1P_MAP_TABLE_NAME, new object_reference_map()}, - {CFG_TC_TO_DSCP_MAP_TABLE_NAME, new object_reference_map()}, - {APP_TUNNEL_DECAP_TABLE_NAME, new object_reference_map()} + {CFG_DSCP_TO_TC_MAP_TABLE_NAME, make_shared()}, + {CFG_MPLS_TC_TO_TC_MAP_TABLE_NAME, make_shared()}, + {CFG_DOT1P_TO_TC_MAP_TABLE_NAME, make_shared()}, + {CFG_TC_TO_QUEUE_MAP_TABLE_NAME, make_shared()}, + {CFG_SCHEDULER_TABLE_NAME, make_shared()}, + {CFG_WRED_PROFILE_TABLE_NAME, make_shared()}, + {CFG_PORT_QOS_MAP_TABLE_NAME, make_shared()}, + {CFG_QUEUE_TABLE_NAME, make_shared()}, + {CFG_TC_TO_PRIORITY_GROUP_MAP_TABLE_NAME, make_shared()}, + {CFG_PFC_PRIORITY_TO_PRIORITY_GROUP_MAP_TABLE_NAME, make_shared()}, + {CFG_PFC_PRIORITY_TO_QUEUE_MAP_TABLE_NAME, make_shared()}, + {CFG_DSCP_TO_FC_MAP_TABLE_NAME, make_shared()}, + {CFG_EXP_TO_FC_MAP_TABLE_NAME, make_shared()}, + {CFG_TC_TO_DOT1P_MAP_TABLE_NAME, make_shared()}, + {CFG_TC_TO_DSCP_MAP_TABLE_NAME, make_shared()}, + {APP_TUNNEL_DECAP_TABLE_NAME, make_shared()} }; map qos_to_ref_table_map = {