Skip to content

Commit 86ecc81

Browse files
authored
Fix literal free when show opcodes is enabled. (#2398)
A literal might be not freed if it is stored in a register, and PARSER_DUMP_BYTE_CODE is enabled, but opcodes are not shown. JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
1 parent 1044523 commit 86ecc81

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

jerry-core/parser/js/js-parser.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -636,19 +636,21 @@ parser_generate_initializers (parser_context_t *context_p, /**< context */
636636
literal_p->prop.length);
637637
literal_pool_p[literal_p->prop.index] = lit_value;
638638
}
639-
640-
if (!context_p->is_show_opcodes
641-
&& !(literal_p->status_flags & LEXER_FLAG_SOURCE_PTR))
642-
{
643-
jmem_heap_free_block ((void *) literal_p->u.char_p, literal_p->prop.length);
644-
}
645639
#else /* !PARSER_DUMP_BYTE_CODE */
646640
if (!(literal_p->status_flags & LEXER_FLAG_UNUSED_IDENT))
647641
{
648642
literal_pool_p[literal_p->prop.index] = literal_p->u.value;
649643
}
650644
#endif /* PARSER_DUMP_BYTE_CODE */
651645
}
646+
647+
#ifdef PARSER_DUMP_BYTE_CODE
648+
if (!context_p->is_show_opcodes
649+
&& !(literal_p->status_flags & LEXER_FLAG_SOURCE_PTR))
650+
{
651+
jmem_heap_free_block ((void *) literal_p->u.char_p, literal_p->prop.length);
652+
}
653+
#endif /* PARSER_DUMP_BYTE_CODE */
652654
}
653655
else if ((literal_p->type == LEXER_FUNCTION_LITERAL)
654656
|| (literal_p->type == LEXER_REGEXP_LITERAL))
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright JS Foundation and other contributors, http://js.foundation
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// This issue was triggered when show opcodes was enabled at compile
16+
// time but not enabled in runtime. A memory leak was created.
17+
18+
function f()
19+
{
20+
var \u0042 = true;
21+
};

0 commit comments

Comments
 (0)