Ticket #732 (closed bug: fixed)

Opened 5 years ago

Last modified 5 years ago

Coroutine contexts not getting freed

Reported by: coke Owned by:
Priority: major Milestone:
Component: core Version: trunk
Severity: high Keywords: tcl blocker memory
Cc: Language: tcl
Patch status: Platform:

Description

running valgrind against tcl to identify memory leaks, I found that the context in Coroutine's invoke is not getting freed. This leaks 24K in a trivial {puts hi} for partcl.

It looks like for Subs, the contexts are getting properly freed. Coroutine extends from Sub, and should be calling Parrot_Sub_destroy. However, that uses the line:

    GETATTR_Sub_sub(interp, pmc, sub);

To determine which Parrot_sub to clean up: I'm guessing doesn't work when you're not a Sub but a Coroutine.

Change History

Changed 5 years ago by coke

Further inspection shows a similar loss of contexts for Subs, so the attr may be examining the proper Parrot_sub for coroutines and getting it wrong in both cases.

Changed 5 years ago by coke

Rebuilding parrot with debug information, here's the 2 related leak traces, against r39344:

==10511== 24,144 (22,288 direct, 1,856 indirect) bytes in 127 blocks are definitely lost in loss record 65 of 67
==10511==    at 0x402601E: malloc (vg_replace_malloc.c:207)
==10511==    by 0x40D7943: mem_sys_allocate (alloc_memory.c:47)
==10511==    by 0x40D87D3: Parrot_alloc_context (alloc_register.c:482)
==10511==    by 0x40D8916: Parrot_set_new_context (alloc_register.c:532)
==10511==    by 0x425D5DE: Parrot_Sub_invoke (sub.pmc:266)
==10511==    by 0x407669C: Parrot_callmethodcc_p_sc (object.ops:80)
==10511==    by 0x41313EF: runops_slow_core (cores.c:462)
==10511==    by 0x413000D: runops_int (main.c:987)
==10511==    by 0x40EC7A0: runops (ops.c:107)
==10511==    by 0x40ECB93: runops_args (ops.c:256)
==10511==    by 0x40EDA45: Parrot_runops_fromc_args (ops.c:325)
==10511==    by 0x40CA8E6: Parrot_runcode (embed.c:1009)
==10511==    by 0x432264E: imcc_run_pbc (main.c:806)
==10511==    by 0x432324B: imcc_run (main.c:1097)
==10511==    by 0x8048967: main (main.c:61)
==10511==
==10511==
==10511== 27,040 bytes in 154 blocks are definitely lost in loss record 66 of 67
==10511==    at 0x402601E: malloc (vg_replace_malloc.c:207)
==10511==    by 0x40D7943: mem_sys_allocate (alloc_memory.c:47)
==10511==    by 0x40D87D3: Parrot_alloc_context (alloc_register.c:482)
==10511==    by 0x40D8916: Parrot_set_new_context (alloc_register.c:532)
==10511==    by 0x425F991: Parrot_Coroutine_invoke (coroutine.pmc:150)
==10511==    by 0x4061885: Parrot_invokecc_p (core.ops:504)
==10511==    by 0x41313EF: runops_slow_core (cores.c:462)
==10511==    by 0x413000D: runops_int (main.c:987)
==10511==    by 0x40EC7A0: runops (ops.c:107)
==10511==    by 0x40ECB93: runops_args (ops.c:256)
==10511==    by 0x40EDA45: Parrot_runops_fromc_args (ops.c:325)
==10511==    by 0x40CA8E6: Parrot_runcode (embed.c:1009)
==10511==    by 0x432264E: imcc_run_pbc (main.c:806)
==10511==    by 0x432324B: imcc_run (main.c:1097)
==10511==    by 0x8048967: main (main.c:61)

Changed 5 years ago by coke

  • version changed from 1.2.0 to trunk

Changed 5 years ago by coke

  • keywords tcl blocker memory added
  • priority changed from normal to major
  • component changed from none to core
  • severity changed from medium to high

There are now 20 tcl spec tests (See Memory Issues at  http://code.google.com/p/partcl/wiki/SpecTestStatus) that are failing with out of memory PANICs when run with a virtual memory limit of 0.5G.

Changed 5 years ago by coke

From a valgrind run against partcl (r440) on parrot (r39470) using

parrot tcl.pbc -e "puts hi"

The size of the context-related leaks are now greatly reduced, but still present. Now including all the alloc_context related leaks instead of just the biggest two.

Totals:

==12199==    definitely lost: 30,925 bytes in 1,510 blocks.
==12199==    indirectly lost: 4,316 bytes in 83 blocks.

Context related leaks:

==12199== 120 bytes in 1 blocks are indirectly lost in loss record 26 of 48
==12199==    at 0x402601E: malloc (vg_replace_malloc.c:207)
==12199==    by 0x40D78B3: mem_sys_allocate (alloc_memory.c:47)
==12199==    by 0x40D8743: Parrot_alloc_context (alloc_register.c:483)
==12199==    by 0x40D8886: Parrot_set_new_context (alloc_register.c:533)
==12199==    by 0x425D42E: Parrot_Sub_invoke (sub.pmc:266)
==12199==    by 0x40EC960: runops_args (ops.c:206)
==12199==    by 0x40ED9B5: Parrot_runops_fromc_args (ops.c:325)
==12199==    by 0x41253E8: run_sub (packfile.c:686)
==12199==    by 0x41255FB: do_1_sub_pragma (packfile.c:748)
==12199==    by 0x4125902: do_sub_pragmas (packfile.c:932)
==12199==    by 0x4125A96: PackFile_append_pbc (packfile.c:4816)
==12199==    by 0x4125B36: compile_or_load_file (packfile.c:4693)
==12199==    by 0x4125E33: Parrot_load_bytecode (packfile.c:4882)
==12199==    by 0x40917CB: Parrot_load_bytecode_sc (core.ops:165)
==12199==    by 0x413124F: runops_slow_core (cores.c:462)
==12199==    by 0x412FE4D: runops_int (main.c:987)
==12199==    by 0x40EC710: runops (ops.c:107)
==12199==    by 0x40ECB03: runops_args (ops.c:256)
==12199==    by 0x40ED9B5: Parrot_runops_fromc_args (ops.c:325)
==12199==    by 0x40CA856: Parrot_runcode (embed.c:1014)
==12199==    by 0x4322A5E: imcc_run_pbc (main.c:801)
==12199==    by 0x432365B: imcc_run (main.c:1092)
==12199==    by 0x8048967: main (main.c:61)

==12199== 136 bytes in 1 blocks are indirectly lost in loss record 28 of 48
==12199==    at 0x402601E: malloc (vg_replace_malloc.c:207)
==12199==    by 0x40D78B3: mem_sys_allocate (alloc_memory.c:47)
==12199==    by 0x40D8743: Parrot_alloc_context (alloc_register.c:483)
==12199==    by 0x40D8886: Parrot_set_new_context (alloc_register.c:533)
==12199==    by 0x425D42E: Parrot_Sub_invoke (sub.pmc:266)
==12199==    by 0x40EC960: runops_args (ops.c:206)
==12199==    by 0x40ED9B5: Parrot_runops_fromc_args (ops.c:325)
==12199==    by 0x41253E8: run_sub (packfile.c:686)
==12199==    by 0x41255FB: do_1_sub_pragma (packfile.c:748)
==12199==    by 0x4125902: do_sub_pragmas (packfile.c:932)
==12199==    by 0x4125A96: PackFile_append_pbc (packfile.c:4816)
==12199==    by 0x4125B36: compile_or_load_file (packfile.c:4693)
==12199==    by 0x4125E33: Parrot_load_bytecode (packfile.c:4882)
==12199==    by 0x40917CB: Parrot_load_bytecode_sc (core.ops:165)
==12199==    by 0x413124F: runops_slow_core (cores.c:462)
==12199==    by 0x412FE4D: runops_int (main.c:987)
==12199==    by 0x40EC710: runops (ops.c:107)
==12199==    by 0x40ECB03: runops_args (ops.c:256)
==12199==    by 0x40ED9B5: Parrot_runops_fromc_args (ops.c:325)
==12199==    by 0x41253E8: run_sub (packfile.c:686)
==12199==    by 0x41255FB: do_1_sub_pragma (packfile.c:748)
==12199==    by 0x4125902: do_sub_pragmas (packfile.c:932)
==12199==    by 0x4125A96: PackFile_append_pbc (packfile.c:4816)
==12199==    by 0x4125B36: compile_or_load_file (packfile.c:4693)
==12199==    by 0x4125E33: Parrot_load_bytecode (packfile.c:4882)
==12199==    by 0x40917CB: Parrot_load_bytecode_sc (core.ops:165)
==12199==    by 0x413124F: runops_slow_core (cores.c:462)
==12199==    by 0x412FE4D: runops_int (main.c:987)
==12199==    by 0x40EC710: runops (ops.c:107)
==12199==    by 0x40ECB03: runops_args (ops.c:256)
==12199==    by 0x40ED9B5: Parrot_runops_fromc_args (ops.c:325)
==12199==    by 0x41253E8: run_sub (packfile.c:686)
==12199==    by 0x41255FB: do_1_sub_pragma (packfile.c:748)
==12199==    by 0x4125902: do_sub_pragmas (packfile.c:932)
==12199==    by 0x4125A96: PackFile_append_pbc (packfile.c:4816)
==12199==    by 0x4125B36: compile_or_load_file (packfile.c:4693)
==12199==    by 0x4125E33: Parrot_load_bytecode (packfile.c:4882)
==12199==    by 0x40917CB: Parrot_load_bytecode_sc (core.ops:165)
==12199==    by 0x413124F: runops_slow_core (cores.c:462)
==12199==    by 0x412FE4D: runops_int (main.c:987)
==12199==    by 0x40EC710: runops (ops.c:107)
==12199==    by 0x40ECB03: runops_args (ops.c:256)
==12199==    by 0x40ED9B5: Parrot_runops_fromc_args (ops.c:325)
==12199==    by 0x40CA856: Parrot_runcode (embed.c:1014)
==12199==    by 0x4322A5E: imcc_run_pbc (main.c:801)
==12199==    by 0x432365B: imcc_run (main.c:1092)
==12199==    by 0x8048967: main (main.c:61)

==12199== 152 bytes in 1 blocks are indirectly lost in loss record 29 of 48
==12199==    at 0x402601E: malloc (vg_replace_malloc.c:207)
==12199==    by 0x40D78B3: mem_sys_allocate (alloc_memory.c:47)
==12199==    by 0x40D8743: Parrot_alloc_context (alloc_register.c:483)
==12199==    by 0x40D8886: Parrot_set_new_context (alloc_register.c:533)
==12199==    by 0x425D42E: Parrot_Sub_invoke (sub.pmc:266)
==12199==    by 0x4076005: Parrot_tailcallmethod_p_sc (object.ops:151)
==12199==    by 0x413124F: runops_slow_core (cores.c:462)
==12199==    by 0x412FE4D: runops_int (main.c:987)
==12199==    by 0x40EC710: runops (ops.c:107)
==12199==    by 0x40ECB03: runops_args (ops.c:256)
==12199==    by 0x40ED9B5: Parrot_runops_fromc_args (ops.c:325)
==12199==    by 0x41253E8: run_sub (packfile.c:686)
==12199==    by 0x41255FB: do_1_sub_pragma (packfile.c:748)
==12199==    by 0x4125902: do_sub_pragmas (packfile.c:932)
==12199==    by 0x4125A96: PackFile_append_pbc (packfile.c:4816)
==12199==    by 0x4125B36: compile_or_load_file (packfile.c:4693)
==12199==    by 0x4125E33: Parrot_load_bytecode (packfile.c:4882)
==12199==    by 0x40917CB: Parrot_load_bytecode_sc (core.ops:165)
==12199==    by 0x413124F: runops_slow_core (cores.c:462)
==12199==    by 0x412FE4D: runops_int (main.c:987)
==12199==    by 0x40EC710: runops (ops.c:107)
==12199==    by 0x40ECB03: runops_args (ops.c:256)
==12199==    by 0x40ED9B5: Parrot_runops_fromc_args (ops.c:325)
==12199==    by 0x40CA856: Parrot_runcode (embed.c:1014)
==12199==    by 0x4322A5E: imcc_run_pbc (main.c:801)
==12199==    by 0x432365B: imcc_run (main.c:1092)
==12199==    by 0x8048967: main (main.c:61)

==12199== 232 bytes in 1 blocks are indirectly lost in loss record 34 of 48
==12199==    at 0x402601E: malloc (vg_replace_malloc.c:207)
==12199==    by 0x40D78B3: mem_sys_allocate (alloc_memory.c:47)
==12199==    by 0x40D8743: Parrot_alloc_context (alloc_register.c:483)
==12199==    by 0x40D8886: Parrot_set_new_context (alloc_register.c:533)
==12199==    by 0x425D42E: Parrot_Sub_invoke (sub.pmc:266)
==12199==    by 0x40EC960: runops_args (ops.c:206)
==12199==    by 0x40ED9B5: Parrot_runops_fromc_args (ops.c:325)
==12199==    by 0x40CA856: Parrot_runcode (embed.c:1014)
==12199==    by 0x4322A5E: imcc_run_pbc (main.c:801)
==12199==    by 0x432365B: imcc_run (main.c:1092)
==12199==    by 0x8048967: main (main.c:61)

==12199== 288 (152 direct, 136 indirect) bytes in 1 blocks are definitely lost in loss record 38 of 48
==12199==    at 0x402601E: malloc (vg_replace_malloc.c:207)
==12199==    by 0x40D78B3: mem_sys_allocate (alloc_memory.c:47)
==12199==    by 0x40D8743: Parrot_alloc_context (alloc_register.c:483)
==12199==    by 0x40D8886: Parrot_set_new_context (alloc_register.c:533)
==12199==    by 0x425D42E: Parrot_Sub_invoke (sub.pmc:266)
==12199==    by 0x407664C: Parrot_callmethodcc_p_sc (object.ops:80)
==12199==    by 0x413124F: runops_slow_core (cores.c:462)
==12199==    by 0x412FE4D: runops_int (main.c:987)
==12199==    by 0x40EC710: runops (ops.c:107)
==12199==    by 0x40ECB03: runops_args (ops.c:256)
==12199==    by 0x40ED9B5: Parrot_runops_fromc_args (ops.c:325)
==12199==    by 0x41253E8: run_sub (packfile.c:686)
==12199==    by 0x41255FB: do_1_sub_pragma (packfile.c:748)
==12199==    by 0x4125902: do_sub_pragmas (packfile.c:932)
==12199==    by 0x4125A96: PackFile_append_pbc (packfile.c:4816)
==12199==    by 0x4125B36: compile_or_load_file (packfile.c:4693)
==12199==    by 0x4125E33: Parrot_load_bytecode (packfile.c:4882)
==12199==    by 0x40917CB: Parrot_load_bytecode_sc (core.ops:165)
==12199==    by 0x413124F: runops_slow_core (cores.c:462)
==12199==    by 0x412FE4D: runops_int (main.c:987)
==12199==    by 0x40EC710: runops (ops.c:107)
==12199==    by 0x40ECB03: runops_args (ops.c:256)
==12199==    by 0x40ED9B5: Parrot_runops_fromc_args (ops.c:325)
==12199==    by 0x40CA856: Parrot_runcode (embed.c:1014)
==12199==    by 0x4322A5E: imcc_run_pbc (main.c:801)
==12199==    by 0x432365B: imcc_run (main.c:1092)
==12199==    by 0x8048967: main (main.c:61)

==12199== 184 bytes in 1 blocks are indirectly lost in loss record 40 of 48
==12199==    at 0x402601E: malloc (vg_replace_malloc.c:207)
==12199==    by 0x40D78B3: mem_sys_allocate (alloc_memory.c:47)
==12199==    by 0x40D8743: Parrot_alloc_context (alloc_register.c:483)
==12199==    by 0x40D8886: Parrot_set_new_context (alloc_register.c:533)
==12199==    by 0x425D42E: Parrot_Sub_invoke (sub.pmc:266)
==12199==    by 0x4061835: Parrot_invokecc_p (core.ops:504)
==12199==    by 0x413124F: runops_slow_core (cores.c:462)
==12199==    by 0x412FE4D: runops_int (main.c:987)
==12199==    by 0x40EC710: runops (ops.c:107)
==12199==    by 0x40ECB03: runops_args (ops.c:256)
==12199==    by 0x40ED9B5: Parrot_runops_fromc_args (ops.c:325)
==12199==    by 0x40CA856: Parrot_runcode (embed.c:1014)
==12199==    by 0x4322A5E: imcc_run_pbc (main.c:801)
==12199==    by 0x432365B: imcc_run (main.c:1092)
==12199==    by 0x8048967: main (main.c:61)

Changed 5 years ago by coke

  • lang set to tcl

Changed 5 years ago by chromatic

Can you reproduce this now?

Changed 5 years ago by coke

  • status changed from new to closed
  • resolution set to fixed

I can no longer reproduce this leak. ./tclsh -e "puts hi" now leaks only

==20482==    definitely lost: 4,078 bytes in 603 blocks.
==20482==      possibly lost: 0 bytes in 0 blocks.
==20482==    still reachable: 112 bytes in 2 blocks.
==20482==         suppressed: 0 bytes in 0 blocks.
Note: See TracTickets for help on using tickets.