From 1b93b4736c63323e7d0a13e6f8a23d544068cdbd Mon Sep 17 00:00:00 2001 From: Nikki Date: Thu, 21 May 2015 16:14:29 -0400 Subject: [PATCH] Fix certain freeing of objects and allow UV_EOF to be passed to plugins --- context.cpp | 8 ++++++++ extension.cpp | 17 ++--------------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/context.cpp b/context.cpp index 779283c..c86bb8d 100644 --- a/context.cpp +++ b/context.cpp @@ -5,6 +5,14 @@ AsyncSocketContext::AsyncSocketContext(IPluginContext* pContext) { } AsyncSocketContext::~AsyncSocketContext() { + if (connect_req != NULL) { + free(connect_req); + } + + if (socket != NULL) { + uv_close((uv_handle_t *) socket, NULL); + } + if (connectCallback) { forwards->ReleaseForward(connectCallback); } diff --git a/extension.cpp b/extension.cpp index 01fe635..0bbcd4a 100644 --- a/extension.cpp +++ b/extension.cpp @@ -73,16 +73,6 @@ void AsyncSocket::OnHandleDestroy(HandleType_t type, void *object) { if(object != NULL) { AsyncSocketContext *ctx = (AsyncSocketContext *) object; - if (ctx->connect_req != NULL) { - uv_close((uv_handle_t *) ctx->connect_req->handle, NULL); - free(ctx->connect_req); - } - - if (ctx->socket != NULL) { - uv_close((uv_handle_t *) ctx->socket, NULL); - free(ctx->socket); - } - delete ctx; } } @@ -134,11 +124,8 @@ void alloc_buffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf) { void on_read(uv_stream_t *client, ssize_t nread, const uv_buf_t *buf) { if (nread < 0) { - if (nread != UV_EOF) { - push_error((AsyncSocketContext*) client->data, nread); - } - //uv_close((uv_handle_t*) client, NULL); - //free(client); + push_error((AsyncSocketContext*) client->data, nread); + // Should we decide to close the socket? For now let's let the plugin handle errors, including EOF. return; }