On Thu, Jun 21, 2012 at 11:39 AM, Yader Hernandez <yader.hernan...@gmail.com> wrote: > I'm trying to reverse an array but I keep getting bizarre results, such as > seg faults > > 0x00000000006d0940 in gc_remove_from_buffer (zv=0x7fffffffb550) at > /home/yaderbh/php-5.4.3/Zend/zend_gc.h:189 > 189 root->next->prev = root->prev; > > or I'll get "PHP Fatal error: Allowed memory size of" errors when trying > to manipulate the array in a script. > > Basically what I'm doing is creating a pointer to zval, allocating and > creating the zval into an array, traversing the existing array and > calling add_index_zval. The position of the index is the current size and > work my way down. > > > hash_table = Z_ARRVAL_P(intern->elements); > > > > ALLOC_INIT_ZVAL(new_elements); > > array_init(new_elements); > > > > zend_hash_internal_pointer_reset_ex(hash_table, &pos); > > > > i = intern->size; > > > > while (zend_hash_get_current_data_ex(hash_table, (void **)¤t, > &pos) == SUCCESS) { > tmp = **current;
Hi: tmp is a stack allocted variable. when this scope is dead, *(&tmp) is undefined value. you should use a heap allocated variable, or just add_ref the current zval thanks > > > > zval_copy_ctor(&tmp); > > > > add_index_zval(new_elements, i, &tmp); > > i--; > > > > zend_hash_move_forward_ex(hash_table, &pos); > > } > > > > zval_ptr_dtor(&intern->elements); > > > > intern->elements = new_elements; > > > Can anyone spot the problem? -- Laruence Xinchen Hui http://www.laruence.com/ -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php