Bug #65949 [Nab]: memory leak and handle leak in shmop
| From: | sakamoto dot ta at saxa dot co dot jp | Date: | Thu, 24 Oct 2013 00:56:34 +0000 |
| Subject: | Bug #65949 [Nab]: memory leak and handle leak in shmop | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-182419@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=65949&edit=1
ID: 65949
User updated by: sakamoto dot ta at saxa dot co dot jp
Reported by: sakamoto dot ta at saxa dot co dot jp
Summary: memory leak and handle leak in shmop
Status: Not a bug
Type: Bug
Package: Unknown/Other Function
Operating System: Windows 2008 Server R2
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
Thank you for answers.
I think to shm_delete to () for each shmop_open is, it is not a specification of the shared memory
of the original.
However, behavior does not change when add a shmop_delete().
Is it not the cause's overwrite the memory address and handle in the following location in the
source?
source:tsrm_win32.c Function shmget()
624: shm->segment = shm_handle;
625: shm->info = info_handle;
626: shm->descriptor = MapViewOfFileEx(shm->info, FILE_MAP_ALL_ACCESS, 0, 0, 0, NULL);
Previous Comments:
------------------------------------------------------------------------
[2013-10-23 16:02:20] ab@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
shm_close() will not unmap the memory segment, but only unregister the key and make that segment
unknown in PHP. It fact that's kind of detaching your script from that segment. To really free
that memory segment, call shmop_delete() before closing. I guess this is not a bug, the logic is the
same in windows and linux. Whereby the system itself might behave different way in sheduling the mem
segment deletion.
------------------------------------------------------------------------
[2013-10-23 00:51:21] sakamoto dot ta at saxa dot co dot jp
Description:
------------
OSï¼Windows 2008 Server R2
PHP:Version 5.3.9
When I call the () shm_close the () shm_open, handle name
\BaseNamedObjects\TSRM_SHM_DESCRIPTOR:x and
\BaseNamedObjects\TSRM_SHM_SEGMENT:x
remains without being released.
The amount of memory used will continue to increase.
This problem does not occur on Linux.
Test script:
---------------
<?php
$shm_id = 0;
$hex_shm_id = 0xff3;
$write_d1 = "test #1 of the shmop() extension";
$write_d2 = "test #2 append data to shared memory segment";
for( ; ; )
{
echo "shm open for create : ";
$shm_id = shmop_open($hex_shm_id, "c", 0644, 1024);
if (!$shm_id) {
die("failed\n");
} else {
echo "ok[".$shm_id."]\n";
}
echo "shm size is: " . ($shm_size = shmop_size($shm_id)) . "\n";
echo "shm write test #1: ";
$written = shmop_write($shm_id, $write_d1, 0);
if ($written != strlen($write_d1)) {
echo "failed\n";
} else {
echo "ok\n";
}
echo "data in memory is: " . shmop_read($shm_id, 0, $written) . "\n";
shmop_close($shm_id);
$shm_id = 0;
sleep(1);
}
?>
Expected result:
----------------
Memory leak and handle leak does not occur.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=65949&edit=1