php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63757 getenv() prosuces memory leak with CGI SAPI
Submitted: 2012-12-13 08:45 UTC Modified: 2012-12-13 09:41 UTC
From: dmitry@php.net Assigned: dmitry (profile)
Status: Closed Package: Filter related
PHP Version: 5.4Git-2012-12-13 (Git) OS: *
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: dmitry@php.net
New email:
PHP Version: OS:

 

 [2012-12-13 08:45 UTC] dmitry@php.net
Description:
------------
The memory leak is well reproducible with debug build and CGI SAPI.
It also possible to see it with valgrind.

$ USE_ZEND_ALLOC=0 valgrind --leak-check=full sapi/cgi/php-cgi env.php

==27371== 136 bytes in 1 blocks are definitely lost in loss record 30 of 73
==27371==    at 0x4008F6F: malloc (vg_replace_malloc.c:270)
==27371==    by 0x84B1704: _emalloc (zend_alloc.c:2423)
==27371==    by 0x84B1B37: _estrndup (zend_alloc.c:2596)
==27371==    by 0x81E275D: php_sapi_filter (filter.c:468)
==27371==    by 0x846FA0E: sapi_getenv (SAPI.c:1020)
==27371==    by 0x8374964: zif_getenv (basic_functions.c:4020)
==27371==    by 0x85189ED: zend_do_fcall_common_helper_SPEC (zend_vm_execute.h:553)
==27371==    by 0x851E497: ZEND_DO_FCALL_SPEC_CONST_HANDLER (zend_vm_execute.h:2302)
==27371==    by 0x8517422: execute_ex (zend_vm_execute.h:356)
==27371==    by 0x8517B11: zend_execute (zend_vm_execute.h:381)
==27371==    by 0x84E06D9: zend_execute_scripts (zend.c:1309)
==27371==    by 0x8466F98: php_execute_script (main.c:2468)

The leak is relate to JIT initialization of PG(http_globals)[TRACK_VARS_ENV]

Test script:
---------------
<?php
getenv("PATH");
?>
OK

Expected result:
----------------
DONE

Actual result:
--------------
DONE
[Thu Dec 13 12:39:18 2012]  Script:  'ZZZZZZZZ�nG'�W�$�'
/home/dmitry/php/php5.4/ext/filter/filter.c(468) :  Freeing 0xF718F3D8 (136 bytes), script=ZZZZZZZZ�nG'�W�$�
=== Total 1 memory leaks detected ===


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-12-13 08:45 UTC] dmitry@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: dmitry
 [2012-12-13 09:40 UTC] dmitry@php.net
Automatic comment on behalf of dmitry@zend.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=35f86d24d81b81e8c755e82d0b2e76d36f4a0201
Log: Fixed bug #63757 (getenv() produces memory leak with CGI SAPI)
 [2012-12-13 09:40 UTC] dmitry@php.net
-Status: Assigned +Status: Closed
 [2012-12-13 09:41 UTC] dmitry@php.net
The fix for this bug has been committed.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.


 [2012-12-19 17:54 UTC] derick@php.net
Automatic comment on behalf of dmitry@zend.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=35f86d24d81b81e8c755e82d0b2e76d36f4a0201
Log: Fixed bug #63757 (getenv() produces memory leak with CGI SAPI)
 [2014-10-07 23:20 UTC] stas@php.net
Automatic comment on behalf of dmitry@zend.com
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=35f86d24d81b81e8c755e82d0b2e76d36f4a0201
Log: Fixed bug #63757 (getenv() produces memory leak with CGI SAPI)
 [2014-10-07 23:31 UTC] stas@php.net
Automatic comment on behalf of dmitry@zend.com
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=35f86d24d81b81e8c755e82d0b2e76d36f4a0201
Log: Fixed bug #63757 (getenv() produces memory leak with CGI SAPI)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 13:01:29 2024 UTC