Skip to content

Commit

Permalink
Fix template memory leak when debugger is running (jerryscript-projec…
Browse files Browse the repository at this point in the history
…t#4572)

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg [email protected]
  • Loading branch information
zherczeg authored Feb 9, 2021
1 parent c2e016e commit 6fd0dfe
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 19 deletions.
24 changes: 12 additions & 12 deletions jerry-core/ecma/base/ecma-helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -1410,6 +1410,18 @@ ecma_bytecode_deref (ecma_compiled_code_t *bytecode_p) /**< byte code pointer */
}
}

#if JERRY_ESNEXT
if (bytecode_p->status_flags & CBC_CODE_FLAGS_HAS_TAGGED_LITERALS)
{
ecma_collection_t *collection_p = ecma_compiled_code_get_tagged_template_collection (bytecode_p);

/* Since the objects in the tagged template collection are not strong referenced anymore by the compiled code
we can treat them as 'new' objects. */
JERRY_CONTEXT (ecma_gc_new_objects) += collection_p->item_count * 2;
ecma_collection_free_template_literal (collection_p);
}
#endif /* JERRY_ESNEXT */

#if JERRY_DEBUGGER
if ((JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED)
&& !(bytecode_p->status_flags & CBC_CODE_FLAGS_DEBUGGER_IGNORE)
Expand Down Expand Up @@ -1444,18 +1456,6 @@ ecma_bytecode_deref (ecma_compiled_code_t *bytecode_p) /**< byte code pointer */
}
#endif /* JERRY_DEBUGGER */

#if JERRY_ESNEXT
if (bytecode_p->status_flags & CBC_CODE_FLAGS_HAS_TAGGED_LITERALS)
{
ecma_collection_t *collection_p = ecma_compiled_code_get_tagged_template_collection (bytecode_p);

/* Since the objects in the tagged template collection are not strong referenced anymore by the compiled code
we can treat them as 'new' objects. */
JERRY_CONTEXT (ecma_gc_new_objects) += collection_p->item_count * 2;
ecma_collection_free_template_literal (collection_p);
}
#endif /* JERRY_ESNEXT */

#if JERRY_MEM_STATS
jmem_stats_free_byte_code_bytes (((size_t) bytecode_p->size) << JMEM_ALIGNMENT_LOG);
#endif /* JERRY_MEM_STATS */
Expand Down
5 changes: 5 additions & 0 deletions tests/debugger/do_next.cmd
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
next
next
n
n
next
n
next
c
17 changes: 14 additions & 3 deletions tests/debugger/do_next.expected
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,19 @@ Connecting to: localhost:5001
Stopped at tests/debugger/do_next.js:15
(jerry-debugger) next
out: next test
Stopped at tests/debugger/do_next.js:17
Stopped at tests/debugger/do_next.js:28
(jerry-debugger) next
out: var cat
Stopped at tests/debugger/do_next.js:18
out: Func
Stopped at tests/debugger/do_next.js:30
(jerry-debugger) n
Stopped at tests/debugger/do_next.js:33
(jerry-debugger) n
out: Func
Stopped at tests/debugger/do_next.js:35
(jerry-debugger) next
Stopped at tests/debugger/do_next.js:39
(jerry-debugger) n
Stopped at tests/debugger/do_next.js:40
(jerry-debugger) next
Stopped at tests/debugger/do_next.js:42
(jerry-debugger) c
22 changes: 18 additions & 4 deletions tests/debugger/do_next.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,29 @@

print("next test");

print ("var cat");
var cat = 'cat';

function test()
{
function f()
{
return 0;
}

print("Func");
return f;
}

var f = test(),
g,
h = f();

{
let a = test(),
b,
c = a();
}

test();

eval("(function () {} `a`)")
gc();

f();

0 comments on commit 6fd0dfe

Please sign in to comment.