#48676 [Opn]: Curl: CURLOPT_FILE increases file handle refcount

From: Date: Wed, 24 Jun 2009 14:21:44 +0000
Subject: #48676 [Opn]: Curl: CURLOPT_FILE increases file handle refcount
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-138768@lists.php.net to get a copy of this message
ID: 48676 User updated by: felix-php at 7val dot com Reported By: felix-php at 7val dot com Status: Open Bug Type: HTTP related Operating System: Debian Linux (etch) PHP Version: 5.2.10 New Comment: The reproduce code is not completly correct: The curl_close() call was meant to be after curl_exec() and before the first fclose(). But interestingly this does not change the behaviour in neither 5.2.9 nor 5.2.10. Previous Comments: ------------------------------------------------------------------------ [2009-06-24 14:17:57] felix-php at 7val dot com Description: ------------ When passing an open, writable file handle to Curl as the CURLOPT_FILE option, the refcount to that file handle is increased without being decreased when calling curl_close. Thus the file handle has to be closed TWICE to actually being flushed and closed. In the reproduce code the file handle is still a valid resource after the first call to fclose(). The bug is reproducable in PHP 5.2.10. In 5.2.9 the code works as expected. In 5.2.10 in ext/curl/interface.c:1440 the call zend_list_addref(Z_LVAL_PP(zvalue)); was added. Maybe the problem origins here, if there is no corresponding delref in curl_close()? Reproduce code: --------------- $fh = fopen('curl.out', 'w'); $c = curl_init('http://example.com'); curl_setopt($c, CURLOPT_FILE, $fh); curl_exec($c); fclose($fh); echo "content 1: ". file_get_contents('curl.out') ."\n"; if (is_resource($fh)) { echo "file still open -> wrong\n"; } else { echo "file closed -> correct\n"; exit; } fclose($fh); if (is_resource($fh)) { echo "file open 2\n"; } curl_close($c); echo "content 2: ". file_get_contents('curl.out') ."\n"; Expected result: ---------------- content 1: <HTML> <HEAD> <TITLE>Example Web Page</TITLE> </HEAD> [..] file closed -> correct Actual result: -------------- content 1: file still open -> wrong content 2: <HTML> <HEAD> <TITLE>Example Web Page</TITLE> </HEAD> [..] ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=48676&edit=1

« previous php.bugs (#138768) next »