xref: /PHP-8.4/ext/ftp/tests/gh10562.phpt (revision c962a96c)
1--TEST--
2GH-10562 (Memory leak with consecutive ftp_nb_fget)
3--EXTENSIONS--
4ftp
5pcntl
6--FILE--
7<?php
8require 'server.inc';
9
10$ftp = ftp_connect('127.0.0.1', $port);
11if (!$ftp) die("Couldn't connect to the server");
12
13var_dump(ftp_login($ftp, 'anonymous', 'IEUser@'));
14
15$local_file = __DIR__ . DIRECTORY_SEPARATOR . "gh10562.txt";
16$fout = fopen($local_file, "w");
17
18// This requests more data, but we don't do the loop to fetch it.
19$ret = ftp_nb_fget($ftp, $fout, "fget", FTP_BINARY, 0);
20var_dump($ret == FTP_MOREDATA);
21
22// This aborts the previous request, fetches the whole "a story" file.
23$ret = ftp_nb_fget($ftp, $fout, "a story", FTP_BINARY, 0);
24while ($ret == FTP_MOREDATA) {
25    $ret = ftp_nb_continue($ftp);
26}
27
28fclose($fout);
29
30echo file_get_contents($local_file), "\n";
31?>
32--CLEAN--
33<?php
34@unlink(__DIR__ . DIRECTORY_SEPARATOR . "gh10562.txt");
35?>
36--EXPECT--
37bool(true)
38bool(true)
39BINARYFooBar
40For sale: baby shoes, never worn.
41