From 94a1728de07d0613bd03ce16f205bcac8e22881a Mon Sep 17 00:00:00 2001 From: Sterling Hughes Date: Fri, 12 Mar 2004 18:41:19 +0000 Subject: [PATCH] avoid a memory leak when a php_curl handle is allocated, but the initialization of a CURL handle fails. --- ext/curl/interface.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/ext/curl/interface.c b/ext/curl/interface.c index 72a42c6228..947173669e 100644 --- a/ext/curl/interface.c +++ b/ext/curl/interface.c @@ -730,20 +730,23 @@ PHP_FUNCTION(curl_init) { zval **url; php_curl *ch; + CURL *cp; int argc = ZEND_NUM_ARGS(); if (argc < 0 || argc > 1 || zend_get_parameters_ex(argc, &url) == FAILURE) { WRONG_PARAM_COUNT; } - alloc_curl_handle(&ch); - TSRMLS_SET_CTX(ch->thread_ctx); - - ch->cp = curl_easy_init(); - if (!ch->cp) { + cp = curl_easy_init(); + if (!cp) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not initialize a new cURL handle"); RETURN_FALSE; } + + alloc_curl_handle(&ch); + TSRMLS_SET_CTX(ch->thread_ctx); + + ch->cp = cp; ch->handlers->write->method = PHP_CURL_STDOUT; ch->handlers->write->type = PHP_CURL_ASCII; -- 2.50.1