mirror of
https://github.com/monero-project/monero.git
synced 2025-05-06 11:34:59 -04:00
Fix an object lifetime bug in net load tests
The commands handler must not be destroyed before the config object, or we'll be accessing freed memory. An earlier attempt at using boost::shared_ptr to control object lifetime turned out to be very invasive, though would be a better solution in theory.
This commit is contained in:
parent
86e9de588c
commit
7dbf76d0da
10 changed files with 45 additions and 16 deletions
|
@ -72,9 +72,11 @@ class async_protocol_handler_config
|
|||
|
||||
friend class async_protocol_handler<t_connection_context>;
|
||||
|
||||
levin_commands_handler<t_connection_context>* m_pcommands_handler;
|
||||
void (*m_pcommands_handler_destroy)(levin_commands_handler<t_connection_context>*);
|
||||
|
||||
public:
|
||||
typedef t_connection_context connection_context;
|
||||
levin_commands_handler<t_connection_context>* m_pcommands_handler;
|
||||
uint64_t m_max_packet_size;
|
||||
uint64_t m_invoke_timeout;
|
||||
|
||||
|
@ -91,8 +93,9 @@ public:
|
|||
template<class callback_t>
|
||||
bool for_connection(const boost::uuids::uuid &connection_id, callback_t cb);
|
||||
size_t get_connections_count();
|
||||
void set_handler(levin_commands_handler<t_connection_context>* handler, void (*destroy)(levin_commands_handler<t_connection_context>*) = NULL);
|
||||
|
||||
async_protocol_handler_config():m_pcommands_handler(NULL), m_max_packet_size(LEVIN_DEFAULT_MAX_PACKET_SIZE)
|
||||
async_protocol_handler_config():m_pcommands_handler(NULL), m_pcommands_handler_destroy(NULL), m_max_packet_size(LEVIN_DEFAULT_MAX_PACKET_SIZE)
|
||||
{}
|
||||
void del_out_connections(size_t count);
|
||||
};
|
||||
|
@ -832,6 +835,15 @@ size_t async_protocol_handler_config<t_connection_context>::get_connections_coun
|
|||
}
|
||||
//------------------------------------------------------------------------------------------
|
||||
template<class t_connection_context>
|
||||
void async_protocol_handler_config<t_connection_context>::set_handler(levin_commands_handler<t_connection_context>* handler, void (*destroy)(levin_commands_handler<t_connection_context>*))
|
||||
{
|
||||
if (m_pcommands_handler && m_pcommands_handler_destroy)
|
||||
(*m_pcommands_handler_destroy)(m_pcommands_handler);
|
||||
m_pcommands_handler = handler;
|
||||
m_pcommands_handler_destroy = destroy;
|
||||
}
|
||||
//------------------------------------------------------------------------------------------
|
||||
template<class t_connection_context>
|
||||
int async_protocol_handler_config<t_connection_context>::notify(int command, const std::string& in_buff, boost::uuids::uuid connection_id)
|
||||
{
|
||||
async_protocol_handler<t_connection_context>* aph;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue