From a8fab5f7496aec7096d57a5caf8d24c9f94083b5 Mon Sep 17 00:00:00 2001 From: Nikki Date: Thu, 21 May 2015 16:55:08 -0400 Subject: [PATCH] Fix reloading plugins causing a segfault with forwards --- context.cpp | 19 ++++--------------- extension.cpp | 2 +- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/context.cpp b/context.cpp index c86bb8d..c761ac4 100644 --- a/context.cpp +++ b/context.cpp @@ -2,6 +2,10 @@ AsyncSocketContext::AsyncSocketContext(IPluginContext* pContext) { this->pContext = pContext; + + connectCallback = forwards->CreateForwardEx(NULL, ET_Single, 1, NULL, Param_Cell); + errorCallback = forwards->CreateForwardEx(NULL, ET_Single, 3, NULL, Param_Cell, Param_Cell, Param_String); + dataCallback = forwards->CreateForwardEx(NULL, ET_Single, 3, NULL, Param_Cell, Param_String, Param_Cell); } AsyncSocketContext::~AsyncSocketContext() { @@ -58,28 +62,13 @@ void AsyncSocketContext::OnData(char* data, ssize_t size) { } bool AsyncSocketContext::SetConnectCallback(funcid_t function) { - if (connectCallback) { - forwards->ReleaseForward(connectCallback); - } - - connectCallback = forwards->CreateForwardEx(NULL, ET_Single, 1, NULL, Param_Cell); return connectCallback->AddFunction(pContext, function); } bool AsyncSocketContext::SetErrorCallback(funcid_t function) { - if (connectCallback) { - forwards->ReleaseForward(errorCallback); - } - - errorCallback = forwards->CreateForwardEx(NULL, ET_Single, 3, NULL, Param_Cell, Param_Cell, Param_String); return errorCallback->AddFunction(pContext, function); } bool AsyncSocketContext::SetDataCallback(funcid_t function) { - if (dataCallback) { - forwards->ReleaseForward(dataCallback); - } - - dataCallback = forwards->CreateForwardEx(NULL, ET_Single, 3, NULL, Param_Cell, Param_String, Param_Cell); return dataCallback->AddFunction(pContext, function); } \ No newline at end of file diff --git a/extension.cpp b/extension.cpp index 0bbcd4a..5325f6b 100644 --- a/extension.cpp +++ b/extension.cpp @@ -72,7 +72,7 @@ AsyncSocketContext* AsyncSocket::GetSocketInstanceByHandle(Handle_t handle) { void AsyncSocket::OnHandleDestroy(HandleType_t type, void *object) { if(object != NULL) { AsyncSocketContext *ctx = (AsyncSocketContext *) object; - + UV_EOF; delete ctx; } }