Skip to content

Commit

Permalink
[ASAN] Fix Indirect Mem Leaks in Orchagent (sonic-net#2869)
Browse files Browse the repository at this point in the history
**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
    sonic-net#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
    sonic-net#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
    sonic-net#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
    sonic-net#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
    sonic-net#9 0x5555594edbd6 in QosOrch::doTask(Consumer&) orchagent/qosorch.cpp:2179
    sonic-net#10 0x5555590c8743 in Consumer::drain() orchagent/orch.cpp:241
    sonic-net#11 0x5555590c8743 in Consumer::drain() orchagent/orch.cpp:238
    sonic-net#12 0x5555590c8743 in Consumer::execute() orchagent/orch.cpp:235
    sonic-net#13 0x555559090dad in OrchDaemon::start() orchagent/orchdaemon.cpp:755
    sonic-net#14 0x555558e9be25 in main orchagent/main.cpp:766
    sonic-net#15 0x7f0a299b6d09 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x23d09)
```
  • Loading branch information
vivekrnv authored Aug 7, 2023
1 parent d54c767 commit 23cb2e5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
12 changes: 6 additions & 6 deletions orchagent/bufferorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ static const vector<sai_buffer_pool_stat_t> 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<object_reference_map>()},
{APP_BUFFER_PROFILE_TABLE_NAME, make_shared<object_reference_map>()},
{APP_BUFFER_QUEUE_TABLE_NAME, make_shared<object_reference_map>()},
{APP_BUFFER_PG_TABLE_NAME, make_shared<object_reference_map>()},
{APP_BUFFER_PORT_INGRESS_PROFILE_LIST_NAME, make_shared<object_reference_map>()},
{APP_BUFFER_PORT_EGRESS_PROFILE_LIST_NAME, make_shared<object_reference_map>()}
};

map<string, string> buffer_to_ref_table_map = {
Expand Down
2 changes: 1 addition & 1 deletion orchagent/orch.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ typedef struct
} referenced_object;

typedef std::map<std::string, referenced_object> object_reference_map;
typedef std::map<std::string, object_reference_map*> type_map;
typedef std::map<std::string, std::shared_ptr<object_reference_map>> type_map;

typedef std::map<std::string, sai_object_id_t> object_map;
typedef std::pair<std::string, sai_object_id_t> object_map_pair;
Expand Down
32 changes: 16 additions & 16 deletions orchagent/qosorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,22 @@ map<string, sai_meter_type_t> 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<object_reference_map>()},
{CFG_MPLS_TC_TO_TC_MAP_TABLE_NAME, make_shared<object_reference_map>()},
{CFG_DOT1P_TO_TC_MAP_TABLE_NAME, make_shared<object_reference_map>()},
{CFG_TC_TO_QUEUE_MAP_TABLE_NAME, make_shared<object_reference_map>()},
{CFG_SCHEDULER_TABLE_NAME, make_shared<object_reference_map>()},
{CFG_WRED_PROFILE_TABLE_NAME, make_shared<object_reference_map>()},
{CFG_PORT_QOS_MAP_TABLE_NAME, make_shared<object_reference_map>()},
{CFG_QUEUE_TABLE_NAME, make_shared<object_reference_map>()},
{CFG_TC_TO_PRIORITY_GROUP_MAP_TABLE_NAME, make_shared<object_reference_map>()},
{CFG_PFC_PRIORITY_TO_PRIORITY_GROUP_MAP_TABLE_NAME, make_shared<object_reference_map>()},
{CFG_PFC_PRIORITY_TO_QUEUE_MAP_TABLE_NAME, make_shared<object_reference_map>()},
{CFG_DSCP_TO_FC_MAP_TABLE_NAME, make_shared<object_reference_map>()},
{CFG_EXP_TO_FC_MAP_TABLE_NAME, make_shared<object_reference_map>()},
{CFG_TC_TO_DOT1P_MAP_TABLE_NAME, make_shared<object_reference_map>()},
{CFG_TC_TO_DSCP_MAP_TABLE_NAME, make_shared<object_reference_map>()},
{APP_TUNNEL_DECAP_TABLE_NAME, make_shared<object_reference_map>()}
};

map<string, string> qos_to_ref_table_map = {
Expand Down

0 comments on commit 23cb2e5

Please sign in to comment.