Fix memory leak in jerry_api_set_object_native_handle.

Related issue: #683

JerryScript-DCO-1.0-Signed-off-by: Ruben Ayrapetyan r.ayrapetyan@samsung.com
This commit is contained in:
Ruben Ayrapetyan 2015-11-02 13:49:52 +03:00
parent c81c730129
commit 9194240ada
2 changed files with 27 additions and 7 deletions

View File

@ -46,18 +46,18 @@ ecma_create_external_pointer_property (ecma_object_t *obj_p, /**< object to crea
|| id == ECMA_INTERNAL_PROPERTY_NATIVE_HANDLE
|| id == ECMA_INTERNAL_PROPERTY_FREE_CALLBACK);
bool ret_val;
bool is_new;
ecma_property_t *prop_p = ecma_find_internal_property (obj_p, id);
if (prop_p == NULL)
{
prop_p = ecma_create_internal_property (obj_p, id);
ret_val = true;
is_new = true;
}
else
{
ret_val = false;
is_new = false;
}
JERRY_STATIC_ASSERT (sizeof (uint32_t) <= sizeof (prop_p->u.internal_property.value));
@ -68,13 +68,24 @@ ecma_create_external_pointer_property (ecma_object_t *obj_p, /**< object to crea
}
else
{
ecma_external_pointer_t *handler_p = ecma_alloc_external_pointer ();
*handler_p = ptr_value;
ecma_external_pointer_t *handler_p;
ECMA_SET_NON_NULL_POINTER (prop_p->u.internal_property.value, handler_p);
if (is_new)
{
handler_p = ecma_alloc_external_pointer ();
ECMA_SET_NON_NULL_POINTER (prop_p->u.internal_property.value, handler_p);
}
else
{
handler_p = ECMA_GET_NON_NULL_POINTER (ecma_external_pointer_t,
prop_p->u.internal_property.value);
}
*handler_p = ptr_value;
}
return ret_val;
return is_new;
} /* ecma_create_external_pointer_property */
/**

View File

@ -179,6 +179,15 @@ handler_construct (const jerry_api_object_t *function_obj_p,
jerry_api_set_object_field_value (this_p->v_object, (jerry_api_char_t *) "value_field", &args_p[0]);
jerry_api_set_object_native_handle (this_p->v_object,
(uintptr_t) 0x0000000000000000ull,
handler_construct_freecb);
uintptr_t ptr;
bool is_ok = jerry_api_get_object_native_handle (this_p->v_object, &ptr);
JERRY_ASSERT (is_ok && ptr == (uintptr_t) 0x0000000000000000ull);
/* check if setting handle for second time is handled correctly */
jerry_api_set_object_native_handle (this_p->v_object,
(uintptr_t) 0x0012345678abcdefull,
handler_construct_freecb);