php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #58541 Calling a method on object returned from (and created inside) a function dies
Submitted: 2009-02-07 15:58 UTC Modified: 2009-02-08 15:11 UTC
From: kannan_jayaprakasam at yahoo dot co dot in Assigned:
Status: Not a bug Package: memcache (PECL)
PHP Version: 5.2.5 OS: Linux
Private report: No CVE-ID: None
 [2009-02-07 15:58 UTC] kannan_jayaprakasam at yahoo dot co dot in
Description:
------------
A particular function does someting like
   $response = new Response();
   $response->setRequest($request);
   return $response;

In the caller of this function I'm calling 
$response->getRequest()->getId() which throws the seg fault below. If within the function I retrieve the $request object (that was just set) and call getId() on it, it is able to call.  All classes are implemented in php extensions. Something seems to go out of scope for no reason; can't figure out why. 


Reproduce code:
---------------
Below are the function implementations:
PHP_METHOD(ooRestResponse, getRequest)
{
    // return the ooRestRequest object associated with response.
    zval *zvalRespObj = getThis();
    CRestResponse *pResponse = (CRestResponse 
*)fetch_resource(zvalRespObj, zvalRespObj, RESTRESPONSE_MEMBER, 
RESTRESPONSE_TYPE, le_restResponse);
    if (pResponse == NULL)
    {
        RETURN_NULL();
    }

    zval* pRequest = pResponse->getRequestImpl();  
    RETURN_ZVAL(pRequest, 0, 0);

}

    /**
     * Set the request object to associate with this response.
    function setRequest ($req)
*/
PHP_METHOD(ooRestResponse, setRequest)
{
    zval *object;

    // Get the parameter - we expext a REQUEST parameter and a string
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &object, 
wssl_php_ooRestRequest_entry) == FAILURE)
    {
        RETURN_NULL();
    }

    zval *zvalRespObj = getThis();
    CRestResponse *pResponse = (CRestResponse 
*)(CRestMessage*)fetch_resource(zvalRespObj, zvalRespObj, 
RESTRESPONSE_MEMBER, RESTRESPONSE_TYPE, le_restResponse);
    if (pResponse == NULL)
    {
        RETURN_NULL();
    }

    pResponse->setRequestImpl(object);
    setupReferenceReturnVal(zvalRespObj, return_value_ptr, 
PHP_REST_RESOURCE_NAME);
}
void setupReferenceReturnVal(zval* zvalRef, zval** return_value, char* 
symbolName)
{
    zval *zvalRefReturn = zvalRef;
    zval_ptr_dtor(return_value);
    if (!zvalRefReturn->is_ref && zvalRefReturn->refcount > 1)
    {
        zval* newRes;
        MAKE_STD_ZVAL(newRes);
        *newRes = *zvalRefReturn;
        zval_copy_ctor(newRes);
        newRes->is_ref = 0;
        newRes->refcount = 1;
        zend_hash_update(&EG(symbol_table), symbolName, 
sizeof(symbolName), &newRes, sizeof(zval*), NULL);
        zvalRefReturn = newRes;
    }

    zvalRefReturn->is_ref = 1;
    zvalRefReturn->refcount++;
    *return_value = zvalRefReturn;
}


Expected result:
----------------
no seg fault

Actual result:
--------------
#0  0x081a3a85 in zend_object_store_get_object (zobject=0x2756e588)
    at 
/home/y/src/oo/packages/oo/php/php-5.2.5/Zend/zend_objects_API.c:255
#1  0x081a2834 in zend_std_get_method (object_ptr=0xbff2b9b4,
    method_name=0xb7f01c40 "getId", method_len=5)
    at 
/home/y/src/oo/packages/oo/php/php-5.2.5/Zend/zend_object_handlers.c:766
#2  0x081f0070 in ZEND_INIT_METHOD_CALL_SPEC_CV_CONST_HANDLER (
    execute_data=0xbff2b990)
    at 
/home/y/src/oo/packages/oo/php/php-5.2.5/Zend/zend_vm_execute.h:21251
#3  0x081a5d15 in execute (op_array=0xb7f018f4)
    at 
/home/y/src/oo/packages/oo/php/php-5.2.5/Zend/zend_vm_execute.h:92
#4  0x081a5f61 in zend_do_fcall_common_helper_SPEC (execute_data=0xbff2c210)
    at 
/home/y/src/oo/packages/oo/php/php-5.2.5/Zend/zend_vm_execute.h:234#5  
0x081a5d15 in execute (op_array=0xb7ef6844)
    at 
/home/y/src/oo/packages/oo/php/php-5.2.5/Zend/zend_vm_execute.h:92
#6  0x081a5f61 in zend_do_fcall_common_helper_SPEC (execute_data=0xbff2c430)
    at 
/home/y/src/oo/packages/oo/php/php-5.2.5/Zend/zend_vm_execute.h:234#7  
0x081a5d15 in execute (op_array=0xb7ee517c)
    at 
/home/y/src/oo/packages/oo/php/php-5.2.5/Zend/zend_vm_execute.h:92
#8  0x0818c8c1 in zend_execute_scripts (type=8, retval=0x0, file_count=3)
    at /home/y/src/oo/packages/oo/php/php-5.2.5/Zend/zend.c:1135
#9  0x08153b9a in php_execute_script (primary_file=0xbff2e890)
    at /home/y/src/oo/packages/oo/php/php-5.2.5/main/main.c:2042
#10 0x082071db in main (argc=2, argv=0xbff2e964)
    at 
/home/y/src/oo/packages/oo/php/php-5.2.5/sapi/cli/php_cli.c:1154


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-02-08 12:12 UTC] mikael at synd dot info
Have you by any chance assigned this bug to the wrong package, how is this related to pecl/memcache?
 [2009-02-08 14:01 UTC] kannan_jayaprakasam at yahoo dot co dot in
This is a php bug. If pecl is not the right place for the bug can you please reassign to php?
 [2009-02-08 15:11 UTC] tony at daylessday dot org
Bugs in custom extensions written by you are by no means PHP bugs.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Wed Dec 01 03:03:40 2021 UTC