php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #58761 Memory leak when using include/include_once
Submitted: 2009-07-13 07:32 UTC Modified: 2009-11-29 14:44 UTC
From: sg at efficientip dot com Assigned:
Status: Closed Package: bcompiler (PECL)
PHP Version: 5.2.9 OS: FreeBSD 6.4
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: sg at efficientip dot com
New email:
PHP Version: OS:

 

 [2009-07-13 07:32 UTC] sg at efficientip dot com
Description:
------------
When using include/include_once, a memory leak occur.

Reproduce code:
---------------
* Compile PHP with --enable-debug flag
* Use a PHP file with includes.

test.php:

<?php
include 'test.inc';
?>

test.inc:
<?php
?>


The following patch remove the leak:
*** bcompiler.c Wed Oct  4 10:45:28 2006
--- bcompiler.c.modif   Sun Jul 12 00:06:37 2009
***************
*** 306,317 ****
               char *path_to_open;
       unsigned char magic[2];
       static int has_gz = -1, has_bz = -1;

       if (has_gz == -1) has_gz = has_gzip_stream_support(TSRMLS_C);
       if (has_bz == -1) has_bz = has_bzip2_stream_support(TSRMLS_C);

       /* try to read magic */
!       stream = php_stream_open_wrapper(file_name, "rb", ENFORCE_SAFE_MODE|USE_PATH|IGNORE_URL_WIN|STREAM_OPEN_FOR_INCLUDE, opened_path);
       if (!stream) {
               BCOMPILER_DEBUG(("error opening file '%s'..\n", file_name));
               return stream;
--- 306,320 ----
               char *path_to_open;
       unsigned char magic[2];
       static int has_gz = -1, has_bz = -1;
+       char    *local_opened_path = NULL;

       if (has_gz == -1) has_gz = has_gzip_stream_support(TSRMLS_C);
       if (has_bz == -1) has_bz = has_bzip2_stream_support(TSRMLS_C);

       /* try to read magic */
!       stream = php_stream_open_wrapper(file_name, "rb", ENFORCE_SAFE_MODE|USE_PATH|IGNORE_URL_WIN|STREAM_OPEN_FOR_INCLUDE, &local_opened_path);
!       if  (local_opened_path)
!               efree(local_opened_path);
       if (!stream) {
               BCOMPILER_DEBUG(("error opening file '%s'..\n", file_name));
               return stream;




Expected result:
----------------
No memory leak

Actual result:
--------------
when starting test.php:

/usr/freebsd-current/php-5.2.9/main/fopen_wrappers.c(668) :  Freeing 0x28C32B4C (11 bytes), script=/tmp/t.php


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-11-29 14:44 UTC] val@php.net
This bug has been fixed in CVS.

In case this was a documentation problem, the fix will show up at the
end of next Sunday (CET) on pecl.php.net.

In case this was a pecl.php.net website problem, the change will show
up on the website in short time.
 
Thank you for the report, and for helping us make PECL better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 12:01:31 2024 UTC