[php-src] Issue #19954: memory leak curl
| From: | YuanchengJiang | Date: | Thu, 25 Sep 2025 05:54:48 +0000 |
| Subject: | [php-src] Issue #19954: memory leak curl | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-250912@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/19954
Author: YuanchengJiang
### Description
The following code:
```php
<?php
function hdr_callback($ch, $data) {
if($GLOBALS['f_file']) {
fclose($GLOBALS['f_file']); $GLOBALS['f_file'] = 0;
curl_setopt($ch, CURLOPT_COOKIE, str_repeat("a", $FILE_size - 1));
}
}
include 'server.inc';
$host = curl_cli_server_start();
$temp_file = __DIR__ . '/body.tmp';
$url = "{$host}/get.inc?test=getpost";
$ch = curl_init();
$f_file = fopen($temp_file, "w") or die("failed to open file\n");
curl_setopt($ch, CURLOPT_HEADERFUNCTION, "hdr_callback");
curl_setopt($ch, CURLOPT_FILE, $f_file);
curl_setopt($ch, CURLOPT_URL, $url);
curl_exec($ch);
```
Resulted in this output:
```
=================================================================
==2017665==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 8192 byte(s) in 1 object(s) allocated from:
#0 0x6810bd in malloc (/home/phpfuzz/WorkSpace/flowfusion/php-src/sapi/cli/php+0x6810bd)
#1 0x7f5c64a37bf4 in _IO_file_doallocate libio/./libio/filedoalloc.c:101:7
SUMMARY: AddressSanitizer: 8192 byte(s) leaked in 1 allocation(s).
```
To reproduce:
```
./php-src/sapi/cli/php ./test.php
```
Commit:
```
e23c6222da50a2c5828a03ad701cd3351b13590d
```
Configurations:
```
CC="clang-12" CXX="clang++-12" CFLAGS="-DZEND_VERIFY_TYPE_INFERENCE"
CXXFLAGS="-DZEND_VERIFY_TYPE_INFERENCE" ./configure --enable-debug
--enable-address-sanitizer --enable-undefined-sanitizer --enable-re2c-cgoto --enable-fpm
--enable-litespeed --enable-phpdbg-debug --enable-zts --enable-bcmath --enable-calendar --enable-dba
--enable-dl-test --enable-exif --enable-ftp --enable-gd --enable-gd-jis-conv --enable-mbstring
--enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvmsg --enable-zend-test
--with-zlib --with-bz2 --with-curl --with-enchant --with-gettext --with-gmp --with-mhash --with-ldap
--with-libedit --with-readline --with-snmp --with-sodium --with-xsl --with-zip --with-mysqli
--with-pdo-mysql --with-pdo-pgsql --with-pgsql --with-sqlite3 --with-pdo-sqlite --with-webp
--with-jpeg --with-freetype --enable-sigchild --with-readline --with-pcre-jit --with-iconv
```
Operating System:
```
Ubuntu 20.04 Host, Docker 0599jiangyc/flowfusion:latest
```
*This report is automatically generated by [FlowFusion](https://github.com/php/flowfusion)*
### PHP Version
```plain
nightly
```
### Operating System
_No response_