php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62995 memcache client Segmentation fault
Submitted: 2012-09-02 10:35 UTC Modified: 2021-02-21 04:22 UTC
Votes:2
Avg. Score:3.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:2 (100.0%)
From: tom916 at qq dot com Assigned: cmb (profile)
Status: No Feedback Package: memcache (PECL)
PHP Version: 5.3Git-2012-09-02 (Git) OS: linux
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: tom916 at qq dot com
New email:
PHP Version: OS:

 

 [2012-09-02 10:35 UTC] tom916 at qq dot com
Description:
------------
<?php
class foo {

    private $memcache = null;

    public function get_memcache() {
        if($this->memcache == null) {
            $tmp = new Memcache();
            $tmp->addServer('localhost', 11211, 1, 1, 1, 15, true, array(
                    $this,
                    'fail'
            ));
            $tmp->setCompressThreshold(8192, 0.2);

            $this->memcache = $tmp;
        }

        return $this->memcache;
    }

    public function fail($host, $port) {

    }
}

/**
 * use static $memcache
 * result is Segmentation fault
 */
class bar {

    private static $memcache = null;

    public function get_memcache() {
        if(self::$memcache == null) {
            $tmp = new Memcache();
            $tmp->addServer('localhost', 11211);
            $tmp->setCompressThreshold(8192, 0.2);
            self::$memcache = $tmp;
        }
        return self::$memcache;
    }
}

/**
 * not static ok
class bar {

    private $memcache = null;

    public function get_memcache() {
        if($this->memcache == null) {
            $tmp = new Memcache();
            $tmp->addServer('localhost', 11211);
            $tmp->setCompressThreshold(8192, 0.2);
            $this->memcache = $tmp;
        }
        return $this->memcache;
    }
}
 */

$bar = new bar();
$memcache = $bar->get_memcache();

$foo = new foo();
$mem = $foo->get_memcache();

echo "ok\n";

----result is--------
 
ok
Segmentation fault


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

not use “ array(
                    $this,
                    'fail'
            )” param is ok


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-09-02 10:37 UTC] tom916 at qq dot com
php-5.3.13
memcache Version => 2.2.6
os Ubuntu 11.04
 [2012-09-02 13:35 UTC] laruence@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a backtrace to see what is happening behind the scenes. To
find out how to generate a backtrace, please read
http://bugs.php.net/bugs-generating-backtrace.php for *NIX and
http://bugs.php.net/bugs-generating-backtrace-win32.php for Win32

Once you have generated a backtrace, please submit it to this bug
report and change the status back to "Open". Thank you for helping
us make PHP better.


 [2012-09-02 13:35 UTC] laruence@php.net
-Status: Open +Status: Feedback
 [2012-09-08 08:57 UTC] tom916 at qq dot com
I use the least php-5.3.16

Configure Command =>  './configure'  '--prefix=/usr/local/php-5.3.16' '--with-mysql=mysqlnd' '--with-gd' '--with-jpeg-dir' '--with-png-dir' '--with-zlib' '--with-freetype-dir' '--enable-gd-native-ttf' '--enable-mbstring' '--enable-sockets' '--with-curl' '--with-pdo-mysql=mysqlnd' '--with-apxs2=/usr/local/httpd/bin/apxs' '--with-tidy' '--enable-dba' '--enable-debug'


root@dev2:/tmp# gdb /usr/local/php-5.3.16/bin/php 
GNU gdb (Ubuntu/Linaro 7.2-1ubuntu11) 7.2
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /usr/local/php-5.3.16/bin/php...done.
(gdb) run /tmp/mem_bug.php
Starting program: /usr/local/php-5.3.16/bin/php /tmp/mem_bug.php
[Thread debugging using libthread_db enabled]
ok
/root/src/php-5.3.16/Zend/zend_hash.c(979) : ht=0x141f698 is being destroyed
/root/src/php-5.3.16/Zend/zend_hash.c(979) : ht=0x141f698 is being destroyed
/root/src/php-5.3.16/Zend/zend_hash.c(70) : Bailed out without a bailout address!

Program exited with code 0377.
(gdb) bt
No stack.
(gdb)
 [2012-09-08 08:57 UTC] tom916 at qq dot com
-Status: Feedback +Status: Open
 [2012-09-08 14:46 UTC] laruence@php.net
hmm, you can simply bypass this issue by define a __destruct to the class like:

class {
.....
public function __destruct() {
    $this->memache = NULL;
}
}

will dig this later.
 [2012-09-08 14:46 UTC] laruence@php.net
-Status: Open +Status: Verified
 [2012-09-08 15:46 UTC] laruence@php.net
Automatic comment from SVN on behalf of laruence
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=327543
Log: Fixed bug #62995 (memcache client Segmentation fault)

Need be reviewed by the author later
 [2012-09-08 15:50 UTC] laruence@php.net
-Status: Verified +Status: Closed -Assigned To: +Assigned To: laruence
 [2012-09-08 15:50 UTC] laruence@php.net
This bug has been fixed in SVN.

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-09-22 08:20 UTC] tom916 at qq dot com
use Singleton result is Segmentation fault
 
-----------------------------
<?php

class foo {

    public static function get_instance() {
        if(! self::$instance) {
            self::$instance = new foo();
        }
        return self::$instance;
    }

    private static $instance;

    public function get_memcache() {
        $memcache = new Memcache();

        $memcache->addServer("localhost", 11211, 1, 1, 1, 15, true, array(
                $this,
                'fail'
        ));
        $this->memcache = $memcache;
        return $memcache;
    }

    public function fail($host, $port) {

    }

}

class bar {

    private static $instance;

 
    public static function get_instance() {
        if(! self::$instance) {
            self::$instance = new bar();
        }
        return self::$instance;
    }
    
    private $memcache;
    
    public function get_memcache() {
        $this->memcache = new Memcache();
        $this->memcache->addServer("localhost", 11211, 1);
        $this->memcache->setCompressThreshold(8192, 0.2);
    }
    
    //// without this funciton Segmentation fault
    //public function __destruct(){
    //	$this->memcache = null;
    //}
}

$foo = foo::get_instance()->get_memcache();
$bar = bar::get_instance()->get_memcache();

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

#0  0x00000000007601f0 in zend_objects_store_del_ref (zobject=0x124a300) at php-5.3.10/Zend/zend_objects_API.c:175
175		GC_ZOBJ_CHECK_POSSIBLE_ROOT(zobject);
(gdb) l
170	
171		Z_ADDREF_P(zobject);
172		zend_objects_store_del_ref_by_handle_ex(handle, Z_OBJ_HT_P(zobject) TSRMLS_CC);
173		Z_DELREF_P(zobject);
174	
175		GC_ZOBJ_CHECK_POSSIBLE_ROOT(zobject);
176	}
177	
178	/*
179	 * Delete a reference to an objects store entry given the object handle.
(gdb)
 [2012-09-22 08:20 UTC] tom916 at qq dot com
-Status: Closed +Status: Assigned
 [2012-09-23 01:48 UTC] hradtke@php.net
I reverted this change revision 327750. The memory leaks prevented me from doing a 
release for PHP 5.4 compatibility. Afterwards, we can work on fixing the memory 
leaks and get this committed.
 [2012-09-23 08:29 UTC] hradtke@php.net
Automatic comment from SVN on behalf of hradtke
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=327754
Log: Fix Bug #62995 - memcache client Segmentation fault
 [2012-09-23 08:31 UTC] hradtke@php.net
-Status: Assigned +Status: Closed
 [2012-09-23 08:31 UTC] hradtke@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.

This code produced some memory leaks before the patch. The patch did introduce 
some more memory leaks, but I have fixed those.

Note to myself to find the other memory leaks: 
valgrind --leak-check=full --show-reachable=yes php -d 
extension=modules/memcache.so tests/pecl63142.php
 [2012-09-23 08:33 UTC] hradtke@php.net
Ignore my last comment. It was for https://bugs.php.net/bug.php?id=63142
 [2012-09-23 08:33 UTC] hradtke@php.net
-Status: Closed +Status: Assigned -Assigned To: laruence +Assigned To: hradtke
 [2017-10-24 06:59 UTC] kalle@php.net
-Status: Assigned +Status: Open -Assigned To: hradtke +Assigned To:
 [2021-02-12 16:37 UTC] cmb@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2021-02-12 16:37 UTC] cmb@php.net
Is this still an issue with memcache 4 or 8?
 [2021-02-21 04:22 UTC] pecl-dev at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 14:01:32 2024 UTC