diff --git a/curlapi.cpp b/curlapi.cpp index ce648e8cd..8c2092456 100644 --- a/curlapi.cpp +++ b/curlapi.cpp @@ -56,7 +56,11 @@ struct curl_slist *HTTPClient::BuildHeaders(struct HTTPRequest request) void HTTPClient::Request(struct HTTPRequest request, IPluginFunction *function, cell_t value) { IChangeableForward *forward = forwards->CreateForwardEx(NULL, ET_Ignore, 2, NULL, Param_Cell, Param_Cell); - forward->AddFunction(function); + if (forward == NULL || !forward->AddFunction(function)) + { + smutils->LogError(myself, "Could not create forward."); + return; + } HTTPRequestThread *thread = new HTTPRequestThread(this, request, forward, value); threader->MakeThread(thread); diff --git a/curlthread.cpp b/curlthread.cpp index ee205efce..6f9e86ac9 100644 --- a/curlthread.cpp +++ b/curlthread.cpp @@ -57,7 +57,9 @@ void HTTPRequestThread::RunThread(IThreadHandle *pHandle) CURL *curl = curl_easy_init(); if (curl == NULL) { - smutils->LogError(myself, "Could not create cURL handle."); + forwards->ReleaseForward(this->forward); + + smutils->LogError(myself, "Could not initialize cURL session."); return; } @@ -108,6 +110,7 @@ void HTTPRequestThread::RunThread(IThreadHandle *pHandle) curl_easy_cleanup(curl); curl_slist_free_all(headers); free(this->request.body); + forwards->ReleaseForward(this->forward); smutils->LogError(myself, "HTTP request failed: %s", error); return; diff --git a/extension.cpp b/extension.cpp index f3a145d87..b4a6382cb 100644 --- a/extension.cpp +++ b/extension.cpp @@ -114,6 +114,7 @@ void RipExt::RunFrame() /* Return early if the plugin was unloaded while the thread was running */ if (forward->GetFunctionCount() == 0) { + forwards->ReleaseForward(forward); this->callbackMutex->Unlock(); return; @@ -123,6 +124,7 @@ void RipExt::RunFrame() Handle_t hndlResponse = handlesys->CreateHandleEx(htHTTPResponseObject, &response, &sec, NULL, NULL); if (hndlResponse == BAD_HANDLE) { + forwards->ReleaseForward(forward); this->callbackMutex->Unlock(); smutils->LogError(myself, "Could not create HTTP response handle."); @@ -136,6 +138,7 @@ void RipExt::RunFrame() handlesys->FreeHandle(hndlResponse, &sec); handlesys->FreeHandle(response.hndlData, &sec); + forwards->ReleaseForward(forward); this->callbackMutex->Unlock(); } diff --git a/smsdk_config.h b/smsdk_config.h index cac83dd66..2d62fff96 100644 --- a/smsdk_config.h +++ b/smsdk_config.h @@ -30,7 +30,7 @@ /* Basic information exposed publicly */ #define SMEXT_CONF_NAME "REST in Pawn" #define SMEXT_CONF_DESCRIPTION "Provides HTTP and JSON natives for plugins" -#define SMEXT_CONF_VERSION "1.0.2" +#define SMEXT_CONF_VERSION "1.0.3" #define SMEXT_CONF_AUTHOR "Tsunami" #define SMEXT_CONF_URL "http://www.tsunami-productions.nl" #define SMEXT_CONF_LOGTAG "RIPEXT"