From: Aaron Krebs Date: Tue, 2 Dec 2014 16:24:05 +0000 (+0100) Subject: Check in trampoline callbacks that mesh instance is not destructed. X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=8d213e55f77461b182e5276823f9ba1ae56ee638;p=meshlink Check in trampoline callbacks that mesh instance is not destructed. --- diff --git a/src/meshlink++.h b/src/meshlink++.h index d7f88fd1..176dd1b6 100644 --- a/src/meshlink++.h +++ b/src/meshlink++.h @@ -149,7 +149,10 @@ namespace meshlink { */ void close() { if(handle) + { + handle->priv = 0; meshlink_close(handle); + } handle=0; } @@ -478,24 +481,32 @@ namespace meshlink { /// static callback trampolines: static void receive_trampoline(meshlink_handle_t* handle, meshlink_node_t* source, const void* data, size_t length) { + if (!(handle->priv)) + return; meshlink::mesh* that = static_cast(handle->priv); that->receive(static_cast(source), data, length); } static void node_status_trampoline(meshlink_handle_t* handle, meshlink_node_t* peer, bool reachable) { + if (!(handle->priv)) + return; meshlink::mesh* that = static_cast(handle->priv); that->node_status(static_cast(peer), reachable); } static void log_trampoline(meshlink_handle_t* handle, log_level_t level, const char* message) { + if (!(handle->priv)) + return; meshlink::mesh* that = static_cast(handle->priv); that->log(level, message); } static bool channel_accept_trampoline(meshlink_handle_t *handle, meshlink_channel *channel, uint16_t port, const void *data, size_t len) { + if (!(handle->priv)) + return; meshlink::mesh* that = static_cast(handle->priv); bool accepted = that->channel_accept(static_cast(channel), port, data, len); if (accepted) @@ -508,12 +519,16 @@ namespace meshlink { static void channel_receive_trampoline(meshlink_handle_t *handle, meshlink_channel *channel, const void* data, size_t len) { + if (!(handle->priv)) + return; meshlink::mesh* that = static_cast(handle->priv); that->channel_receive(static_cast(channel), data, len); } static void channel_poll_trampoline(meshlink_handle_t *handle, meshlink_channel *channel, size_t len) { + if (!(handle->priv)) + return; meshlink::mesh* that = static_cast(handle->priv); that->channel_poll(static_cast(channel), len); }