Re: Fwd: zend_std_get_method : Address 0xffffffff is not stack'd, malloc'd or (recently) free'd

From: Date: Mon, 31 Mar 2014 10:38:26 +0000
Subject: Re: Fwd: zend_std_get_method : Address 0xffffffff is not stack'd, malloc'd or (recently) free'd
References: 1  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
On Mon, 2014-03-31 at 00:39 +0200, Kajetan Dolinar wrote:
> Hi there,
> 
> I may have missed the right list but please consider my problem as it 

This is a good place, usually I suggest using pecl-dev as there are less
mails, so less chance of being overseen.

> needs Zend internals expert attention and may be a Zend bug. I am 
> developing a PHP extension and have stmbled over a fault. The excerpt 
> from the valgrind output on that fault says
> 
> Invalid read of size 4
>   at 0x44EAA4: zend_std_get_method (zend_object_handlers.c:847)
>   by 0x47A035: ZEND_INIT_METHOD_CALL_SPEC_VAR_CONST_HANDLER
> (zend_vm_execute.h:10461)
>   by 0x452D1D: execute (zend_vm_execute.h:107)
>   by 0x42C398: zend_execute_scripts (zend.c:1236)
>   by 0x1: ???
> Address 0xffffffff is not stack'd, malloc'd or (recently) free'd

This won't help much, without any further information like code or at
least PHP version. Apparently 5.3 was the last version where
zend_std_get_method is lose to line 847 in later versions it's starting
somewhere in the thousands ... but that's too little to guess the fault.

> The reason most probably lies within my code, but I don't have enough 
> PHP Zend engine hacking experience to get to it by myself - it's my 
> first PHP extension. Much obliged for intuitions from experienced for 
> what could bring about such kind of fault.

Reduce you ode till it works or share more details ..

> However, there are leaks because I have turned off my own system for 
> memory control. I am using quite a complicated interplay of allocated 
> memory as well as references to static data. I use
> 
>   void * phxy_data_start() { return (void *) &etext; }
>   void * phxy_variable_start() { return (void *) &edata; }
>   void * phxy_heap_start() { return (void *) &end; }
>   void * phxy_stack_start() { return sbrk(0); }
>   unsigned char phxy_is_heap(void * data) {
>       return (phxy_heap_start() <= data && data < phxy_stack_start());
>   }
>   unsigned char phxy_is_data(void * data) {
>       return (data >= phxy_data_start());
>   }
> 
> to find out which data need freeing and which not (i.e. before any 
> free() I check with phxy_is_heap()). But for my PHP extension I dear not 
> use this so that phxy_is_heap() always returns false for any data - 
> hence memory leaks. Please advise me of a safe PHP Zend analogue for 
> that approach.

Depends on what you want to use that memory for and what you optimize
for. i.e. if you want to stick data in PHP data structures it should be
emalloc'd with one block per item so PHP an free it.

johannes



Thread (8 messages)

« previous php.internals (#73486) next »