]> git.meshlink.io Git - meshlink/commitdiff
Check in trampoline callbacks that mesh instance is not destructed.
authorAaron Krebs <aaron.krebs@everbase.net>
Tue, 2 Dec 2014 16:24:05 +0000 (17:24 +0100)
committerGuus Sliepen <guus@meshlink.io>
Sat, 27 Dec 2014 17:40:18 +0000 (18:40 +0100)
src/meshlink++.h

index d7f88fd119e8c9c9b51149858142b930d3a85da5..176dd1b6d95d3c1c08bb25750990407a58d28caf 100644 (file)
@@ -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<mesh*>(handle->priv);
                        that->receive(static_cast<node*>(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<mesh*>(handle->priv);
                        that->node_status(static_cast<node*>(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<mesh*>(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<mesh*>(handle->priv);
                        bool accepted = that->channel_accept(static_cast<meshlink::channel*>(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<mesh*>(handle->priv);
                        that->channel_receive(static_cast<meshlink::channel*>(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<mesh*>(handle->priv);
                        that->channel_poll(static_cast<meshlink::channel*>(channel), len);
                }