bug60570.phpt 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. --TEST--
  2. Bug #60570 (Stream context leaks when http request fails)
  3. --SKIPIF--
  4. <?php require 'server.inc'; http_server_skipif(); ?>
  5. --INI--
  6. allow_url_fopen=1
  7. --FILE--
  8. <?php
  9. require 'server.inc';
  10. function do_test() {
  11. $responses = array(
  12. "data://text/plain,HTTP/1.0 404 Not Found\r\n\r\n",
  13. "data://text/plain,HTTP/1.0 404 Not Found\r\n\r\n",
  14. "data://text/plain,HTTP/1.0 404 Not Found\r\n\r\n"
  15. );
  16. ['pid' => $pid, 'uri' => $uri] = http_server($responses, $output);
  17. $a = $b = count(get_resources());
  18. $i = 3;
  19. while ($i--) {
  20. $context = stream_context_create(array('http'=>array('timeout'=>1)));
  21. file_get_contents($uri, 0, $context);
  22. unset($context);
  23. $b = $a;
  24. $a = count(get_resources());
  25. }
  26. http_server_kill($pid);
  27. echo "leak? penultimate iteration: $b, last one: $a\n";
  28. var_dump($a == $b);
  29. }
  30. do_test();
  31. ?>
  32. --EXPECTF--
  33. Warning: file_get_contents(http://%s:%d): Failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found
  34. in %s on line %d
  35. Warning: file_get_contents(http://%s:%d): Failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found
  36. in %s on line %d
  37. Warning: file_get_contents(http://%s:%d): Failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found
  38. in %s on line %d
  39. leak? penultimate iteration: %d, last one: %d
  40. bool(true)