php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #60509 pcntl_signal doesn't decrease ref-count of old handler when setting SIG_DFL
Submitted: 2011-12-13 09:30 UTC Modified: 2014-11-29 13:53 UTC
From: mplomer at gmx dot de Assigned:
Status: Closed Package: PCNTL related
PHP Version: 5.3.8 OS: Debian Squeeze
Private report: No CVE-ID:
 [2011-12-13 09:30 UTC] mplomer at gmx dot de
Description:
------------
When overwriting an old signal handler (that references "$this" for example) with SIG_DFL, the reference counter on $this is not decreased, so when unsetting the object, it cannot be freed.

My current workaround: When overwriting the signal handler with an empty function before ("function() {}"), the ref-count is correctly decreased (WTF?!), and the instance is immediately freed, when unsetting the object.

Test script:
---------------
class Test {
    public function __construct() {
        pcntl_signal(SIGUSR1, array($this, 'signalHandler'), false);
        //pcntl_signal(SIGUSR1, function() {}); // destruct works correctly when commenting in
        pcntl_signal(SIGUSR1, SIG_DFL);
    }

    public function signalHandler() {
    }

    public function __destruct() {
        echo '__destruct' . PHP_EOL;
    }
}

$test = new Test();

echo 'unsetting' . PHP_EOL;
unset($test);
echo 'end' . PHP_EOL;


Expected result:
----------------
unsetting
__destruct
end

Actual result:
--------------
unsetting
end
__destruct

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-11-29 13:52 UTC] jpauli@php.net
Automatic comment on behalf of jpauli
Revision: http://git.php.net/?p=php-src.git;a=commit;h=19b5bc8ce22b1476eb084a8b64c137bb8b17d674
Log: Fix #60509, pcntl_signal doesn't decrease ref-count of old handler
 [2014-11-29 13:52 UTC] jpauli@php.net
-Status: Open +Status: Closed
 [2014-11-29 13:52 UTC] jpauli@php.net
Automatic comment on behalf of jpauli
Revision: http://git.php.net/?p=php-src.git;a=commit;h=19b5bc8ce22b1476eb084a8b64c137bb8b17d674
Log: Fix #60509, pcntl_signal doesn't decrease ref-count of old handler
 [2014-11-29 13:53 UTC] jpauli@php.net
Automatic comment on behalf of jpauli
Revision: http://git.php.net/?p=php-src.git;a=commit;h=19b5bc8ce22b1476eb084a8b64c137bb8b17d674
Log: Fix #60509, pcntl_signal doesn't decrease ref-count of old handler
 [2014-11-29 13:53 UTC] jpauli@php.net
-Status: Closed +Status: Feedback
 [2014-11-29 13:53 UTC] jpauli@php.net
Please try using this snapshot:

  http://snaps.php.net/php5.5-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/


 [2014-12-05 07:00 UTC] ab@php.net
Automatic comment on behalf of jpauli
Revision: http://git.php.net/?p=php-src.git;a=commit;h=19b5bc8ce22b1476eb084a8b64c137bb8b17d674
Log: Fix #60509, pcntl_signal doesn't decrease ref-count of old handler
 [2014-12-05 07:00 UTC] ab@php.net
-Status: Feedback +Status: Closed
 [2014-12-06 12:57 UTC] mplomer at gmx dot de
Cool, tnx!
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Fri Feb 24 01:01:37 2017 UTC