php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #11199 fread() doesn't free allocated memory
Submitted: 2001-05-30 12:09 UTC Modified: 2002-03-18 15:16 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: yohgaki at hotmail dot com Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 4.0 Latest CVS (2001-05-30) OS: Linux
Private report: No CVE-ID: None
 [2001-05-30 12:09 UTC] yohgaki at hotmail dot com
fopen() does not work for URLs.
I got following results.

fopen('http://www.php.net/','r');

/home/yohgaki/public_html/test/ezhttpbench.php(87) : Warning
- stat failed for http://www.php.net/ (errno=2 - No such
file or directory)

Note: ezhttpbench.php ia a simple benchmark program uses
fopen().(URL: http://developer.ez.no/)



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-05-30 20:19 UTC] yohgaki at hotmail dot com
PHP4.0.6RC1 has this problem also.

If I open with partial URI like 'http://www.php.net', I get
following error log. (Both 4.0.7-dev and 4.0.6RC1)

http_fopen_wrapper.c(213) :  Freeing 0x081B5B94 (128 bytes),
script=/home/yohgaki/public_html/test/ezhttpbench.php




 [2001-05-30 20:45 UTC] yohgaki at hotmail dot com
This gdb output may be useful.

fopen('http://www.php.net/', 'r') makes apahce exit.

(gdb) run -X
Starting program: /usr/sbin/httpd -X

Program exited with code 01.
(gdb)

./configure \
--enable-debug \
--with-dmalloc \
--with-apxs \
--disable-short-tags \
--disable-mysql \
--without-mysql \
--enable-bcmath  \
--enable-ftp \
--enable-inline-optimization \
--enable-shmop \
--enable-sysvsem \
--enable-sysvshm \
--enable-sockets \
--enable-mbstring \
--enable-mbstr-enc-trans \
--enable-memory-limit \
--enable-wddx \
--with-bz2 \
--with-curl \
--with-ftp \
--with-iconv \
--with-mhash \
--with-mcrypt \
--with-pgsql \
--with-regex=system \
--with-zlib \
--with-gd=/usr \
--enable-gd-native-ttf \
--with-freetype-dir=/usr/local \
--with-jpeg-dir=/usr \
--with-png-dir=/usr \
--with-xpm-dir=/usr/X11R6 \

Apache: 1.3.20
Mod-SSL: 2.8.4
PHP: 4.0.6RC1, 4.0.7-dev (2000-5-30)
OS: RedHat 7.0.1 (glibc 2.2, kernel 2.2.19)


 [2001-05-30 22:17 UTC] sniper@php.net
Works for me just fine. Fix your system.

--Jani

 [2001-05-31 01:05 UTC] yohgaki at hotmail dot com
The real problem was caused in different part of code.

Apahce exit with code 01 when there is following loop or
like. (file can be local or remote. Tested with 4.0.6RC1)

for($i = 0; $i <10; $i++) {
$fp = fopen($HTTP_POST_VARS['file'],'r');
$data = fread($fp, 10000000);
fclose($fp);
}

Opening the same file is only useful for benchmarks, though.

It seems there is no smilar open report for this.
I'll open new report for this, if you would like.

----------------------------------
<?php
if (isset($HTTP_POST_VARS['file']))
{
	for($i = 0; $i <10; $i++) {
		$fp = fopen($HTTP_POST_VARS['file'],'r');
		$data = fread($fp, 10000000);
		fclose($fp);
	}
}
?>
<html>
<head>
<title>fopen() test2</title>
</head>

<body>
<pre>
<form method="post">
<input type="text" name="file" value="<?php
@print($HTTP_POST_VARS['file']); ?>">
<input type="submit" name="submit" value="Execute fopen()">
</form>
<p>
<?php
if (isset($data))
{
	echo "\n==OUTPUT==\n";
	
	print(htmlspecialchars($data));

	echo "\n==END==\n";
	
}
else
{
	echo " No files are opened\n";
}

?>
</p>
</pre>
</body>
</html>
------------------------------------------

Looks like the loop triggers a bug.

PS: ezhttpdbench.php had useless line looks like
$filesize = filesize(<url's file descriptor>);
This line makes me confuse.

 [2001-05-31 12:30 UTC] sniper@php.net
This works for me just fine. There is something wrong
in your system / sources.  (I tried with PHP 4.0.6RC1)

--Jani

 [2001-05-31 23:33 UTC] yohgaki at hotmail dot com
I think you don't have memory limit.

PHP allocates memory specified length for fread() and keep it. (This case is 10000001 for every fread()) If it does not require that amount of memory, it would be nice to resize size of allocated memory since size of files are not known for remote files.

If this is designed behavior, I can live with that, though. But, it is better to be logged. I see no error log for this. (I use E_ALL and logs errors)

To make this clear, I changed status to open again.

Thanks for your time.

-- 
for($i = 0; $i <10; $i++) {
   $fp = fopen($HTTP_POST_VARS['file'],'r');
   $data = fread($fp, 10000000);
   fclose($fp);
}
--

#0  exit (status=1) at exit.c:40
#1  0x4051b38c in _emalloc (size=10000001) at zend_alloc.c:186
#2  0x405b4c94 in php_if_fread (ht=2, return_value=0x815ee6c, this_ptr=0x0, return_value_used=1) at file.c:2010
#3  0x4052cc84 in execute (op_array=0x816048c) at ./zend_execute.c:1504
#4  0x4053f5b1 in zend_execute_scripts (type=8, file_count=3) at zend.c:749
#5  0x40550f5b in php_execute_script (primary_file=0xbffff5c0) at main.c:1206
#6  0x4054d73a in apache_php_module_main (r=0x81533f8, display_source_mode=0) at sapi_apache.c:89
#7  0x4054e0d9 in send_php (r=0x81533f8, display_source_mode=0, filename=0x0) at mod_php4.c:539
#8  0x4054e112 in send_parsed_php (r=0x81533f8) at mod_php4.c:550
#9  0x8055957 in ap_invoke_handler ()
#10 0x8069c0b in process_request_internal ()
#11 0x8069c6c in ap_process_request ()
#12 0x8061041 in child_main ()
#13 0x8061210 in make_child ()
#14 0x8061384 in startup_children ()
#15 0x80619d3 in standalone_main ()
#16 0x806220b in main ()
#17 0x400b5b5c in __libc_start_main (main=0x8061e58 <main>, argc=2, ubp_av=0xbffff8c4, init=0x804fa50 <_init>, 
    fini=0x8099ffc <_fini>, rtld_fini=0x4000d634 <_dl_fini>, stack_end=0xbffff8bc)
    at ../sysdeps/generic/libc-start.c:129
(gdb) f 1
#1  0x4051b38c in _emalloc (size=10000001) at zend_alloc.c:186
186		CHECK_MEMORY_LIMIT(size, SIZE);

 [2001-06-01 00:02 UTC] sniper@php.net
You are absolutely right. This should cause something
else than mere 'exit(1)' by the Zend engine. 

(I do have memory_limit..it was set to 1500M :)

--Jani

 [2001-10-20 23:30 UTC] sniper@php.net
updated summary

 [2001-10-20 23:30 UTC] sniper@php.net
oops..typo.

 [2002-03-18 15:16 UTC] wez@php.net
This bug has been fixed in CVS.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Jun 27 23:01:31 2024 UTC