jerryscript-project / iotjs

Platform for Internet of Things with JavaScript http://www.iotjs.net

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Memory leak in 'setTimeout' on exceptions

LaszloLango opened this issue · comments

IoT.js version:
Checked revision: 67b1de3
Build command: tools/build.py --clean
OS:
Ubuntu 16.04
Test case:
setTimeout(function() { throw "error" }, 100);
Backtrace:

The test case a memory leak.

with x86_64-linux target:

==30636== Memcheck, a memory error detector
==30636== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==30636== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==30636== Command: ./build/x86_64-linux/debug/bin/iotjs tmp.js
==30636== 
uncaughtException: error
==30636== 
==30636== HEAP SUMMARY:
==30636==     in use at exit: 104 bytes in 1 blocks
==30636==   total heap usage: 41 allocs, 40 frees, 5,257 bytes allocated
==30636== 
==30636== 104 bytes in 1 blocks are definitely lost in loss record 1 of 1
==30636==    at 0x4C2FB55: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==30636==    by 0x41608F: iotjs_buffer_allocate (iotjs_util.c:68)
==30636==    by 0x42586D: iotjs_timerwrap_create (iotjs_module_timer.c:27)
==30636==    by 0x4262FB: Timer (iotjs_module_timer.c:156)
==30636==    by 0x4627BF: ecma_op_function_call (ecma-function-object.c:467)
==30636==    by 0x462BF1: ecma_op_function_construct_simple_or_external (ecma-function-object.c:598)
==30636==    by 0x462DB6: ecma_op_function_construct (ecma-function-object.c:666)
==30636==    by 0x47A7F1: opfunc_construct (vm.c:483)
==30636==    by 0x47F679: vm_execute (vm.c:2798)
==30636==    by 0x47F8BF: vm_run (vm.c:2873)
==30636==    by 0x462747: ecma_op_function_call (ecma-function-object.c:406)
==30636==    by 0x47A6B3: opfunc_call (vm.c:425)
==30636== 
==30636== LEAK SUMMARY:
==30636==    definitely lost: 104 bytes in 1 blocks
==30636==    indirectly lost: 0 bytes in 0 blocks
==30636==      possibly lost: 0 bytes in 0 blocks
==30636==    still reachable: 0 bytes in 0 blocks
==30636==         suppressed: 0 bytes in 0 blocks
==30636== 
==30636== For counts of detected and suppressed errors, rerun with: -v
==30636== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)

Status update: I have a fix for this, but I cannot add the testcase because the lack of the JS testrunner. I must fix the testrunner at first.

@LaszloLango Could you explain more about the lack of the JS testrunner? In fact, our plan is to replace JS testrunner with python testrunner. So I would not put more time on JS test runner.

Another question occurred: Is there any reason we cannot replace JS testrunner with python runner in travis?

@glistening the problem is that if a test fails (even it is an expected fail) the environment does not clean up properly. For example active timers could run in the background and can trigger false negative test failures later. AFAIK we can replace the JS testrunner with the python testrunner. It could make things easier. I'll open a PR for that. Should we keep the JS testrunner in the repository or remove it completely?

@LaszloLango Please replace JS testrunner, but we need time to inform the potential JS test user that it will be removed. What about adding message for JS testrunner invocation like "JS testrunner will be removed, please use python runner instead.", and keep JS testrunner for some days, and remove it?

@glistening Ok, we can do it.

@glistening I had some issue when tried to replace the testrunner, so I am not sure when I could upload the final patch.

@LaszloLango Could you share the issue here or by IRC? We would like to deprecate JS testrunner to reduce maintenance cost.

@glistening sorry for the late answer. One of my biggest problems at the moment is the mixed usage of travis_check.py and precommit.py. The second problem is to build and use the 32bit binary on 64bit systems (needed for address sanitizer job).

@LaszloLango I can't understand fully what is related to deprecating JS test runner and the mixed usage of travis_check.py and precommit.py. Could you explain more in #1229? If merging into one file helps deprecating JS testrunner, it could be a good backing example.

Second, do you mean python runner could not run 32bit binary on 64 bit systems? We may add the feature js-test-runner after completing js-test-runner restructuring.

@glistening not exactly. The testrunner is able to run any binary. The problem comes from the separation of the build and the test. I wanted to change the travis jobs to use the python testrunner. This is why travis_check.py and precommit.py related. I'll open a PR soon.