cvs: php4 /ext/curl curl.c php_curl.h

From: Date: Wed, 22 Nov 2000 15:46:13 +0000
Subject: cvs: php4 /ext/curl curl.c php_curl.h
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-2738@lists.php.net to get a copy of this message
stas Wed Nov 22 07:46:13 2000 EDT Modified files: /php4/ext/curl curl.c php_curl.h Log: Fix memory leaks in cURL. cURL doesn't free strings we pass to him, so let PHP do it. Index: php4/ext/curl/curl.c diff -u php4/ext/curl/curl.c:1.26 php4/ext/curl/curl.c:1.27 --- php4/ext/curl/curl.c:1.26 Wed Nov 22 07:19:59 2000 +++ php4/ext/curl/curl.c Wed Nov 22 07:46:13 2000 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: curl.c,v 1.26 2000/11/22 15:19:59 sterling Exp $ */ +/* $Id: curl.c,v 1.27 2000/11/22 15:46:13 stas Exp $ */ #include "php.h" @@ -267,6 +267,9 @@ return SUCCESS; } +static void curl_free_string(void **string) { + efree(*string); +} /* {{{ proto string curl_version(void) Return the CURL version string. */ @@ -296,6 +299,8 @@ } memset(curl_handle, 0, sizeof(php_curl)); + zend_llist_init(&curl_handle->to_free,sizeof(char *),curl_free_string,0); + curl_handle->cp = curl_easy_init(); if (!curl_handle->cp) { php_error(E_ERROR, "Cannot initialize CURL Handle"); @@ -308,6 +313,7 @@ urlstr = estrndup(Z_STRVAL_PP(url), Z_STRLEN_PP(url)); curl_easy_setopt(curl_handle->cp, CURLOPT_URL, urlstr); + zend_llist_add_element(&curl_handle->to_free,&urlstr); } curl_easy_setopt(curl_handle->cp, CURLOPT_NOPROGRESS, 1); @@ -375,6 +381,7 @@ copystr = estrndup(Z_STRVAL_PP(curl_value), Z_STRLEN_PP(curl_value)); ret = curl_easy_setopt(curl_handle->cp, option, copystr); + zend_llist_add_element(&curl_handle->to_free,&copystr); } break; @@ -793,6 +800,7 @@ { php_curl *curl_handle = (php_curl *)rsrc->ptr; curl_easy_cleanup(curl_handle->cp); + zend_llist_clean(&curl_handle->to_free); efree(curl_handle); } /* }}} */ Index: php4/ext/curl/php_curl.h diff -u php4/ext/curl/php_curl.h:1.13 php4/ext/curl/php_curl.h:1.14 --- php4/ext/curl/php_curl.h:1.13 Fri Oct 27 12:10:21 2000 +++ php4/ext/curl/php_curl.h Wed Nov 22 07:46:13 2000 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_curl.h,v 1.13 2000/10/27 19:10:21 sterling Exp $ */ +/* $Id: php_curl.h,v 1.14 2000/11/22 15:46:13 stas Exp $ */ #ifndef _PHP_CURL_H #define _PHP_CURL_H @@ -56,6 +56,7 @@ int cerrno; char error[CURL_ERROR_SIZE+1]; CURL *cp; + zend_llist to_free; } php_curl; typedef struct {

« previous php.cvs (#2738) next »