|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #16635 dio_read() leaks memory
Submitted: 2002-04-16 11:11 UTC Modified: 2002-11-03 07:27 UTC
From: Jorfen at web dot de Assigned: sterling (profile)
Status: Closed Package: Unknown/Other Function
PHP Version: 4.2.0 OS: x86/Linux
Private report: No CVE-ID: None
 [2002-04-16 11:11 UTC] Jorfen at web dot de
I am using the RC4 of php4.2.0 with Apache/1.3.24 (Unix).
Every time dio_read() is called in a script, the htttpd process uses more and more memory.

$o = dio_read($fp,100000);

would let httpd grow by ca. x times of 100000.
unset($o) will not get the memory back. the httpd process would keep its size until the script terminates.

Needing to call dio_read repeatidly makes it even worse. And using 1024 bytes blocks only slows the process of growing down.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2002-04-18 19:12 UTC]
Assigned to Sterling who is the maintainer of this extension..

 [2002-04-20 12:09 UTC]
Cannot reproduce - this shouldn't happen.
 [2002-11-03 04:40 UTC] juha dot tuominen at tuotoi dot net
I have the memory leaking problem with dio_read() as well. The PHP versio I use is 4.2.2 with DirectIO extension in an embedded Linux box. 

I have an X10 home automation software written with PHP and it runs as a daemon. The serial port is configured to be non-blocking. I check if there is any data available about 10 times a second (it's a busyloop with usleep(100000) in it). The checking is done as follows:


After running the daemon for about 20 hours, I always get the following error message:

Fatal error:  Allowed memory size of 2097152 bytes exhausted (tried to allocate 2 bytes) in /mnt/data/plugins/X10/html/x10_wrapper.php on line 76

Line 76 is the one above with dio_read(). I would really need a fix for this or I'm forced to write a nasty kill-the-process-and-then-restart-it-again-just-to-make-it-stay-alive
piece of script to be ran by cron.
 [2002-11-03 07:27 UTC]
there is a leak when the call "fails" in this case.
Please try copying this file into your local source:
It should act as a drop-in replacement for ext/dio/dio.c.

If you don't want to risk that, then look for 
PHP_FUNCTION(dio_read) in that file, and then these lines:
    res = read(f->fd, data, bytes);
    if (res <= 0) {
         efree(data);  // <-- this line fixes the leak

PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Mon Aug 08 00:05:45 2022 UTC