mirror of
https://github.com/monero-project/monero.git
synced 2025-05-06 12:05:03 -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
|
@ -52,6 +52,7 @@ namespace levin
|
|||
class levin_client_async
|
||||
{
|
||||
levin_commands_handler* m_pcommands_handler;
|
||||
void (*commands_handler_destroy)(levin_commands_handler*);
|
||||
volatile uint32_t m_is_stop;
|
||||
volatile uint32_t m_threads_count;
|
||||
::critical_section m_send_lock;
|
||||
|
@ -85,9 +86,9 @@ namespace levin
|
|||
::critical_section m_connection_lock;
|
||||
net_utils::blocked_mode_client m_transport;
|
||||
public:
|
||||
levin_client_async():m_pcommands_handler(NULL), m_is_stop(0), m_threads_count(0), m_invoke_data_ready(0), m_invoke_is_active(0)
|
||||
levin_client_async():m_pcommands_handler(NULL), commands_handler_destroy(NULL), m_is_stop(0), m_threads_count(0), m_invoke_data_ready(0), m_invoke_is_active(0)
|
||||
{}
|
||||
levin_client_async(const levin_client_async& /*v*/):m_pcommands_handler(NULL), m_is_stop(0), m_threads_count(0), m_invoke_data_ready(0), m_invoke_is_active(0)
|
||||
levin_client_async(const levin_client_async& /*v*/):m_pcommands_handler(NULL), commands_handler_destroy(NULL), m_is_stop(0), m_threads_count(0), m_invoke_data_ready(0), m_invoke_is_active(0)
|
||||
{}
|
||||
~levin_client_async()
|
||||
{
|
||||
|
@ -97,11 +98,16 @@ namespace levin
|
|||
|
||||
while(boost::interprocess::ipcdetail::atomic_read32(&m_threads_count))
|
||||
::Sleep(100);
|
||||
|
||||
set_handler(NULL);
|
||||
}
|
||||
|
||||
void set_handler(levin_commands_handler* phandler)
|
||||
void set_handler(levin_commands_handler* phandler, void (*destroy)(levin_commands_handler*) = NULL)
|
||||
{
|
||||
if (commands_handler_destroy && m_pcommands_handler)
|
||||
(*commands_handler_destroy)(m_pcommands_handler);
|
||||
m_pcommands_handler = phandler;
|
||||
m_pcommands_handler_destroy = destroy;
|
||||
}
|
||||
|
||||
bool connect(uint32_t ip, uint32_t port, uint32_t timeout)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue