From:             [EMAIL PROTECTED]
Operating system: Linux
PHP version:      5.2CVS-2008-12-11 (CVS)
PHP Bug Type:     cURL related
Bug description:  memleak on handles duplicated with curl_copy_handle()

Description:
------------
When an handle is copied with curl_copy_handle(), its ability to free
memory used by strings is disabled.

In ext/curl/interface.c near line 1215 :

  zend_llist_copy(&dupch->to_free.str, &ch->to_free.str);
  /* Don't try to free copied strings, they're free'd when the original
handle is destroyed */
  dupch->to_free.str.dtor = NULL;
  zend_llist_copy(&dupch->to_free.slist, &ch->to_free.slist);
  zend_llist_copy(&dupch->to_free.post, &ch->to_free.post);

1. New strings allocated by this new handle will have "NULL" as dtor
2. slist and post will still be free'd on both handles. Freeing one handle
first also probably breaks the second handle
3. The copied handle will have unexpected behaviour with libcurl <7.17.0
if the source handle is freed before the copied handle.

Two options exists here:

1. Disable this function for people who don't have at least libcurl
7.17.0, and let libcurl handle duplication of strings, etc.. (it now does
this automatically, cf bug #45161).
2. Manually duplicate all options that are set in the source curl handle
and register them in newly allocated handle on curl_copy_handle(). This can
lead to errors as we do not keep record of all set options.

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

$ch = curl_init();

for($i = 0; $i < 2048; ++$i) {
        $ch2 = curl_copy_handle($ch);

        curl_setopt($ch2, CURLOPT_URL, 'http://localhost/test/tset/est');

        curl_close($ch2);

        var_dump(memory_get_usage());
}


Expected result:
----------------
(always the same int dumped)

Actual result:
--------------
[...]
int(415128)
int(415256)
int(415384)
int(415512)
int(415640)
int(415768)
int(415896)
int(416024)
int(416152)
int(416280)
int(416408)
int(416536)
int(416664)
[Thu Dec 11 06:50:37 2008]  Script:  'curl_memleak.php'
ext/curl/interface.c(1342) :  Freeing 0x0198CB78 (31 bytes),
script=curl_memleak.php
Last leak repeated 2047 times
=== Total 2048 memory leaks detected ===


-- 
Edit bug report at http://bugs.php.net/?id=46832&edit=1
-- 
Try a CVS snapshot (PHP 5.2):        
http://bugs.php.net/fix.php?id=46832&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):        
http://bugs.php.net/fix.php?id=46832&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):        
http://bugs.php.net/fix.php?id=46832&r=trysnapshot60
Fixed in CVS:                        
http://bugs.php.net/fix.php?id=46832&r=fixedcvs
Fixed in CVS and need be documented: 
http://bugs.php.net/fix.php?id=46832&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=46832&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=46832&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=46832&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=46832&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=46832&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=46832&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=46832&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=46832&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=46832&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=46832&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=46832&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=46832&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=46832&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=46832&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=46832&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=46832&r=mysqlcfg

Reply via email to