mirror of
https://github.com/phpv8/v8js.git
synced 2024-11-10 02:38:42 +00:00
Fix memory leak: The get_properties handler owns the returned hashtable.
This commit is contained in:
parent
b4d560dd52
commit
dba6322812
@ -188,6 +188,7 @@ struct php_v8js_object {
|
|||||||
v8::Persistent<v8::Value> v8obj;
|
v8::Persistent<v8::Value> v8obj;
|
||||||
int flags;
|
int flags;
|
||||||
v8::Isolate *isolate;
|
v8::Isolate *isolate;
|
||||||
|
HashTable *properties;
|
||||||
};
|
};
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
25
v8js.cc
25
v8js.cc
@ -305,8 +305,16 @@ static HashTable *php_v8js_v8_get_properties(zval *object TSRMLS_DC) /* {{{ */
|
|||||||
php_v8js_object *obj = (php_v8js_object *) zend_object_store_get_object(object TSRMLS_CC);
|
php_v8js_object *obj = (php_v8js_object *) zend_object_store_get_object(object TSRMLS_CC);
|
||||||
HashTable *retval;
|
HashTable *retval;
|
||||||
|
|
||||||
ALLOC_HASHTABLE(retval);
|
if (obj->properties == NULL) {
|
||||||
zend_hash_init(retval, 0, NULL, ZVAL_PTR_DTOR, 0);
|
if (GC_G(gc_active)) {
|
||||||
|
/* the garbage collector is running, don't create more zvals */
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
ALLOC_HASHTABLE(obj->properties);
|
||||||
|
zend_hash_init(obj->properties, 0, NULL, ZVAL_PTR_DTOR, 0);
|
||||||
|
} else {
|
||||||
|
zend_hash_clean(obj->properties);
|
||||||
|
}
|
||||||
|
|
||||||
v8::Isolate *isolate = obj->isolate;
|
v8::Isolate *isolate = obj->isolate;
|
||||||
v8::Locker locker(isolate);
|
v8::Locker locker(isolate);
|
||||||
@ -316,8 +324,8 @@ static HashTable *php_v8js_v8_get_properties(zval *object TSRMLS_DC) /* {{{ */
|
|||||||
v8::Context::Scope temp_scope(temp_context);
|
v8::Context::Scope temp_scope(temp_context);
|
||||||
v8::Local<v8::Value> v8obj = v8::Local<v8::Value>::New(isolate, obj->v8obj);
|
v8::Local<v8::Value> v8obj = v8::Local<v8::Value>::New(isolate, obj->v8obj);
|
||||||
|
|
||||||
if (php_v8js_v8_get_properties_hash(v8obj, retval, obj->flags, isolate TSRMLS_CC) == SUCCESS) {
|
if (php_v8js_v8_get_properties_hash(v8obj, obj->properties, obj->flags, isolate TSRMLS_CC) == SUCCESS) {
|
||||||
return retval;
|
return obj->properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -326,7 +334,7 @@ static HashTable *php_v8js_v8_get_properties(zval *object TSRMLS_DC) /* {{{ */
|
|||||||
|
|
||||||
static HashTable *php_v8js_v8_get_debug_info(zval *object, int *is_temp TSRMLS_DC) /* {{{ */
|
static HashTable *php_v8js_v8_get_debug_info(zval *object, int *is_temp TSRMLS_DC) /* {{{ */
|
||||||
{
|
{
|
||||||
*is_temp = 1;
|
*is_temp = 0;
|
||||||
return php_v8js_v8_get_properties(object TSRMLS_CC);
|
return php_v8js_v8_get_properties(object TSRMLS_CC);
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
@ -460,6 +468,12 @@ static void php_v8js_v8_free_storage(void *object, zend_object_handle handle TSR
|
|||||||
{
|
{
|
||||||
php_v8js_object *c = (php_v8js_object *) object;
|
php_v8js_object *c = (php_v8js_object *) object;
|
||||||
|
|
||||||
|
if (c->properties) {
|
||||||
|
zend_hash_destroy(c->properties);
|
||||||
|
FREE_HASHTABLE(c->properties);
|
||||||
|
c->properties = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
zend_object_std_dtor(&c->std TSRMLS_CC);
|
zend_object_std_dtor(&c->std TSRMLS_CC);
|
||||||
|
|
||||||
c->v8obj.Reset();
|
c->v8obj.Reset();
|
||||||
@ -495,6 +509,7 @@ void php_v8js_create_v8(zval *res, v8::Handle<v8::Value> value, int flags, v8::I
|
|||||||
c->v8obj.Reset(isolate, value);
|
c->v8obj.Reset(isolate, value);
|
||||||
c->flags = flags;
|
c->flags = flags;
|
||||||
c->isolate = isolate;
|
c->isolate = isolate;
|
||||||
|
c->properties = NULL;
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user