[php-src] Issue #10562: Memory leak with consecutive ftp_nb_fget

From: Date: Fri, 10 Feb 2023 21:09:30 +0000
Subject: [php-src] Issue #10562: Memory leak with consecutive ftp_nb_fget
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-243708@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/10562 Author: nielsdos ### Description The following code: ```php <?php include "ext/ftp/tests/server.inc"; $conn_id = ftp_connect("127.0.0.1", $port) or die("no connection to ftp"); ftp_login($conn_id, 'anonymous', 'IEUser@'); $fout = fopen("test-output.tmp", "w"); $ret = ftp_nb_fget($conn_id, $fout, "fget", FTP_BINARY, 10); $ret = ftp_nb_fget($conn_id, $fout, "fget", FTP_BINARY, 10); fclose($fout); ``` Resulted in this output: ``` Warning: ftp_nb_fget(): Closing data Connection. in /home/niels/php-src/memleak.php on line 11 [Fri Feb 10 21:53:49 2023] Script: '/home/niels/php-src/memleak.php' /home/niels/php-src/ext/ftp/ftp.c(1631) : Freeing 0x00007f3176889000 (4108 bytes), script=/home/niels/php-src/memleak.php === Total 1 memory leaks detected === ``` But I expected this output instead: ``` Warning: ftp_nb_fget(): Closing data Connection. in /home/niels/php-src/memleak.php on line 11 ``` Seems like the ftp->data pointer gets overwritten before the previous action is done(? not sure, I haven't looked into detail). In any case the pointer is overwritten and the old one isn't freed. Discovered while developing PR #10525. ### PHP Version PHP >=8.1 ### Operating System Linux

« previous php.bugs (#243708) next »