]> granicus.if.org Git - php/commitdiff
avoid a memory leak when a php_curl handle is allocated, but the initialization
authorSterling Hughes <sterling@php.net>
Fri, 12 Mar 2004 18:41:19 +0000 (18:41 +0000)
committerSterling Hughes <sterling@php.net>
Fri, 12 Mar 2004 18:41:19 +0000 (18:41 +0000)
of a CURL handle fails.

ext/curl/interface.c

index 72a42c6228ec87ddcfe3fd8f17f078837822ab1e..947173669e8a8c0efb12b89cce16696aa236b2d3 100644 (file)
@@ -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;