ID:               33011
 Updated by:       [EMAIL PROTECTED]
 Reported By:      joe at bs0 dot com
-Status:           Open
+Status:           Feedback
 Bug Type:         Semaphore related
 Operating System: windows xp
 PHP Version:      4.3.11, 5.0.4
 New Comment:

This code outputs for me:

shared memory block marked for deletion.
block closed.
PHP Warning:  shmop_open(): unable to attach or create shared memory
segment in /www/index.php on line 27

Warning: shmop_open(): unable to attach or create shared memory segment
in /www/index.php on line 27
Could not open previously deleted block.


Previous Comments:
------------------------------------------------------------------------

[2005-05-15 02:34:02] joe at bs0 dot com

as short as I can make it:

<?php
$toWrite = 'test string';       
$shm_len = strlen($toWrite);

$shm_id = shmop_open(0xff3, "c", 0644, $shm_len);

shmop_write($shm_id, $toWrite, 0);
shmop_close($shm_id);

$shm_id = shmop_open(0xff3, "a", 0, 0); 
$data = shmop_read($shm_id, 0, $shm_len);       
shmop_close($shm_id);

$shm_id = shmop_open(0xff3, "w", 0, 0); 

if (!shmop_delete($shm_id)) {
        echo "Couldn't mark shared memory block for deletion.<br/>";
}
else {
        echo "shared memory block marked for deletion.<br/>";   
}

shmop_close($shm_id);
echo 'block closed.<br/>';

$shm_id = shmop_open(0xff3, "a", 0, 0); 

if($shm_id) {
        $data = shmop_read($shm_id, 0, $shm_len);       
        shmop_close($shm_id);   
        
        echo 'ERROR: Previously deleted block able to be opened.<br/>';
        echo 'Data read : "' . $data . '"';
}
else {
        echo 'Could not open previously deleted block.<br/>';
}
?>

------------------------------------------------------------------------

[2005-05-15 02:00:15] [EMAIL PROTECTED]

Provide a *short* and *readable* reproduce script without any "actions"
and cases. Just a plain script that runs and shows wrong behaviour.

------------------------------------------------------------------------

[2005-05-14 21:03:26] joe at bs0 dot com

I realize this, please see the linked to test case, shmop_close is
being called, so shm_nattch is zero. (there are no other processes
using this memory.

There are a couple problems in tsrm_win32.c:

when shmop_delete is called, the block is correctly flagged as needing
to be deleted(descriptor->shm_perm.key = -1), however nothing is done
with this again.  
The call to shmdt should call UnmapViewOfFile and CloseHandle on the
appropriate handles.  
After this, the shm_pair needs to be removed from the global array
held.
The only time the files are unmapped/handles closed is in the
destructor.  This is the wrong place to do it since the destructor is
only called when the sapi module is unloaded.

I've changed the code to take care of these problems, just need to do a
bit more testing.  I'll try to submit a patch later in the day.

------------------------------------------------------------------------

[2005-05-14 19:34:15] [EMAIL PROTECTED]

"The segment will only actually be destroyed after the last process
detaches it (i.e., when the shm_nattch member of the associated
structure shmid_ds is zero)." 
(c) man shmctl
Also read user notes here: http://php.net/shmop_delete

------------------------------------------------------------------------

[2005-05-12 04:33:53] joe at bs0 dot com

Description:
------------
Tested with iis/php5.0.4, iis/php4.3.11, apache2/php4.3.11 - same
problem.  after a succesful call to shmop_delete, the shared memory can
still be opened, and the previous values read in.  Delete call seems to
have no effect.

Each step is done in new request:
1)Create shared memory block, populate with string.
2)open block, read in string
3)open block, call shmop_delete (returns true)
4)open block, read in string <- should not be able to open block for
reading at this point.


looks to be the same as Bug #28965, this bug has status of No Feedback,
so opening a new one.

Reproduce code:
---------------
Code to reproduce:
http://bs0.com/shmop/shmop_test.php.txt

Expected result:
----------------
leave only one step uncommented at a time, at step 4, the open should
fail and no data should be read in.

Actual result:
--------------
After step 4, memory is still opened/data is read in.


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=33011&edit=1

Reply via email to