php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #36813 curl_close causes segfault when accessing members in object
Submitted: 2006-03-21 14:10 UTC Modified: 2006-03-21 17:47 UTC
From: olaf at 7val dot com Assigned:
Status: Closed Package: cURL related
PHP Version: 5.1.2 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: olaf at 7val dot com
New email:
PHP Version: OS:

 

 [2006-03-21 14:10 UTC] olaf at 7val dot com
Description:
------------
curl_close causes a segfault when accessing a member variable after the call (see code below) when CURLOPT_RETURNTRANSFER is true and CURLOPT_HEADERFUNCTION is set to a member function.

Calling 
curl_setopt($this->curl, CURLOPT_HEADERFUNCTION,array(&$this, 'readHeader'));

again in __destruct (before curl_close) makes the segfault go away.

Adding the line:
zval_copy_ctor(ch->handlers->write_header->func_name);
in ext/curl/interface.c  line 1152 seems to fix it, but I don't know if it produces a memory leak.



Reproduce code:
---------------
<?php

class CurlTest {
	var $curl;
    var $url;

	function readHeader($ch, $data) 
	{
		return strlen($data);
	}

	function __construct($url)
	{		
		$this->curl = curl_init($url);
		curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($this->curl, CURLOPT_HEADERFUNCTION, array(&$this, 'readHeader'));
		curl_setopt($this->curl, CURLOPT_URL, $url);
		$this->url = $url;
	}

	function __destruct()
	{
		if (is_resource($this->curl)) {
			curl_close($this->curl);
		}
		$x = $this->url;
	}

	function exec() 
	{
		curl_exec($this->curl);
	}
}


$t = new CurlTest('http://www.google.de');
$t->exec();
$t = null;

?>


Expected result:
----------------
No segfault

Actual result:
--------------
Segfault

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-03-21 15:38 UTC] iliaa@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.1-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.1-win32-latest.zip

Appears to work fine in latest CVS.
 [2006-03-21 17:17 UTC] olaf at 7val dot com
CVS sanpshot works fine for me
 [2006-03-21 17:19 UTC] olaf at 7val dot com
Accidentally changed Summary, reverted it
 [2006-03-21 17:47 UTC] tony2001@php.net
Works fine -> closed.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 24 04:01:31 2024 UTC