xref: /PHP-7.4/ext/curl/tests/bug45161.phpt (revision 079905ac)
1--TEST--
2Bug #45161 (Reusing a curl handle leaks memory)
3--SKIPIF--
4<?php
5include 'skipif.inc';
6$curl_version = curl_version();
7if ($curl_version['version_number'] < 0x071100) {
8	exit("skip: test works only with curl >= 7.17.0");
9}
10?>
11--FILE--
12<?php
13include 'server.inc';
14$host = curl_cli_server_start();
15
16// Fill memory for test
17$ch = curl_init();
18$fp = fopen(PHP_OS_FAMILY === 'Windows' ? 'nul' : '/dev/null', 'w');
19
20/*
21$i = $start = $end = 100000.00;
22for ($i = 0; $i < 100; $i++) {
23	curl_setopt($ch, CURLOPT_URL, 'http://127.0.0.1:9/');
24	curl_setopt($ch, CURLOPT_FILE, $fp);
25	curl_exec($ch);
26}
27*/
28
29// Start actual test
30$start = memory_get_usage() + 1024;
31for($i = 0; $i < 1024; $i++) {
32	curl_setopt($ch, CURLOPT_URL, "{$host}/get.inc");
33	curl_setopt($ch, CURLOPT_FILE, $fp);
34	curl_exec($ch);
35}
36if ($start < memory_get_usage()) {
37	echo 'FAIL';
38} else {
39	echo 'PASS';
40}
41echo "\n";
42fclose($fp);
43unset($fp);
44?>
45--EXPECT--
46PASS
47