Skip to content

Commit 385b988

Browse files
Fix of memory leak in ecma_op_function_construct_simple_or_external.
Related issue: #121 JerryScript-DCO-1.0-Signed-off-by: Ruben Ayrapetyan [email protected]
1 parent 64522db commit 385b988

File tree

2 files changed

+40
-11
lines changed

2 files changed

+40
-11
lines changed

jerry-core/ecma/operations/ecma-function-object.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -741,23 +741,24 @@ ecma_op_function_construct_simple_or_external (ecma_object_t *func_obj_p, /**< F
741741
prototype_magic_string_p),
742742
ret_value);
743743

744-
// 6.
745-
ecma_object_t *prototype_p;
744+
// 1., 2., 4.
745+
ecma_object_t *obj_p;
746746
if (ecma_is_value_object (func_obj_prototype_prop_value))
747747
{
748-
prototype_p = ecma_get_object_from_value (func_obj_prototype_prop_value);
749-
ecma_ref_object (prototype_p);
748+
// 6.
749+
obj_p = ecma_create_object (ecma_get_object_from_value (func_obj_prototype_prop_value),
750+
true,
751+
ECMA_OBJECT_TYPE_GENERAL);
750752
}
751753
else
752754
{
753755
// 7.
754-
prototype_p = ecma_builtin_get (ECMA_BUILTIN_ID_OBJECT_PROTOTYPE);
755-
}
756+
ecma_object_t *prototype_p = ecma_builtin_get (ECMA_BUILTIN_ID_OBJECT_PROTOTYPE);
756757

757-
// 1., 2., 4.
758-
ecma_object_t *obj_p = ecma_create_object (prototype_p, true, ECMA_OBJECT_TYPE_GENERAL);
758+
obj_p = ecma_create_object (prototype_p, true, ECMA_OBJECT_TYPE_GENERAL);
759759

760-
ecma_deref_object (prototype_p);
760+
ecma_deref_object (prototype_p);
761+
}
761762

762763
// 3.
763764
/*
@@ -781,19 +782,21 @@ ecma_op_function_construct_simple_or_external (ecma_object_t *func_obj_p, /**< F
781782
// 9.
782783
if (ecma_is_value_object (call_completion))
783784
{
784-
ecma_deref_object (obj_p);
785-
786785
obj_value = ecma_copy_value (call_completion, true);
787786
}
788787
else
789788
{
790789
// 10.
790+
ecma_ref_object (obj_p);
791791
obj_value = ecma_make_object_value (obj_p);
792792
}
793793

794794
ret_value = ecma_make_normal_completion_value (obj_value);
795795

796796
ECMA_FINALIZE (call_completion);
797+
798+
ecma_deref_object (obj_p);
799+
797800
ECMA_FINALIZE (func_obj_prototype_prop_value);
798801

799802
ecma_deref_ecma_string (prototype_magic_string_p);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2015 Samsung Electronics Co., Ltd.
2+
// Copyright 2015 University of Szeged.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
try {
17+
function f_1() {
18+
v_1 + v_1;
19+
}
20+
21+
f_1(new f_1);
22+
23+
assert (false);
24+
} catch (e) {
25+
assert (e instanceof ReferenceError);
26+
}

0 commit comments

Comments
 (0)