php.net |  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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: Jorfen at web dot de
New email:
PHP Version: OS:

 

 [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.

ex.:
$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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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

 [2002-04-20 12:09 UTC] sterling@php.net
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:

$data=dio_read($fp,1);

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.
-Juha
 [2002-11-03 07:27 UTC] wez@php.net
juha.tuominen@tuotoi.net:
there is a leak when the call "fails" in this case.
Please try copying this file into your local source:
http://cvs.php.net/co.php/php4/ext/dio/dio.c?login=2&r=1.21&p=1
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
         RETURN_NULL();
    }

 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Wed Aug 10 04:05:44 2022 UTC