Skip to content

Commit

Permalink
Fix invalid memory reads when GC is on
Browse files Browse the repository at this point in the history
  • Loading branch information
sjinks committed Jul 25, 2013
1 parent 6fdc9c0 commit 46f3955
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
12 changes: 8 additions & 4 deletions ext/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,15 @@ static void phalcon_config_unset_dimension(zval *object, zval *offset TSRMLS_DC)
*/
static HashTable* phalcon_config_get_properties(zval* object TSRMLS_DC)
{
phalcon_config_object* obj = fetchPhalconConfigObject(object TSRMLS_CC);
HashTable* props = zend_std_get_properties(object TSRMLS_CC);
zval *tmp;
HashTable* props = zend_std_get_properties(object TSRMLS_CC);

if (!GC_G(gc_active)) {
phalcon_config_object* obj = fetchPhalconConfigObject(object TSRMLS_CC);
zval *tmp;

zend_hash_copy(props, obj->props, (copy_ctor_func_t)zval_add_ref, (void*)&tmp, sizeof(zval*));
}

zend_hash_copy(props, obj->props, (copy_ctor_func_t)zval_add_ref, (void*)&tmp, sizeof(zval*));
return props;
}

Expand Down
8 changes: 7 additions & 1 deletion unit-tests/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,5 +284,11 @@ public function testIniConfigDirective()

$this->assertEquals($actual, $expected);
}
}

public function testConfigWithMergeAndGarbageCollection()
{
$config = new Phalcon\Config(array('test1' => 1, 'test2' => 2));
$config->merge(new Phalcon\Config(array('test2')));
gc_collect_cycles();
}
}

0 comments on commit 46f3955

Please sign in to comment.