Skip to content

Leaking memory related to mpv/Lua #3463

@low-batt

Description

@low-batt

System and IINA version:

  • macOS 11.4
  • IINA 1.2.0

Expected behavior:

IINA should not leak memory

Actual behavior:

IINA 1.2.0 (mpv 0.32.0) is leaking objects related to mpv processing of Lua scripts:

Output from leaks:
Process:         IINA [95803]
Path:            /Users/USER/Library/Developer/Xcode/DerivedData/iina-echacgeisxgbwucwumppkhklmnkd/Build/Products/Debug/IINA.app/Contents/MacOS/IINA
Load Address:    0x10caec000
Identifier:      com.colliderli.iina
Version:         1.2.0 (129)
Code Type:       X86-64
Platform:        macOS
Parent Process:  debugserver [95805]

Date/Time:       2021-07-27 15:54:57.894 -0400
Launch Time:     2021-07-27 15:53:58.595 -0400
OS Version:      macOS 11.4 (20F71)
Report Version:  7
Analysis Tool:   /usr/bin/leaks

Physical footprint:         172.6M
Physical footprint (peak):  196.7M
----

leaks Report Version: 4.0, multi-line stacks
Process 95803: 126917 nodes malloced for 92851 KB
Process 95803: 89 leaks for 6848 total leaked bytes.

STACK OF 12 INSTANCES OF 'ROOT CYCLE: malloc<64>':
24  libsystem_pthread.dylib               0x111449af7 thread_start + 15
23  libsystem_pthread.dylib               0x11144e1b8 _pthread_start + 224
22  libmpv.1.dylib                        0x111001ba2 script_thread + 114
21  libmpv.1.dylib                        0x110ff6533 load_lua + 147
20  liblua.5.1.dylib                      0x10f49163f lua_cpcall + 45
19  liblua.5.1.dylib                      0x10f495180 luaD_pcall + 68
18  liblua.5.1.dylib                      0x10f49464f luaD_rawrunprotected + 84
17  liblua.5.1.dylib                      0x10f494f08 luaD_call + 80
16  liblua.5.1.dylib                      0x10f494ab6 luaD_precall + 455
15  libmpv.1.dylib                        0x110ff6aeb run_lua + 1307
14  liblua.5.1.dylib                      0x10f4915db lua_pcall + 105
13  liblua.5.1.dylib                      0x10f495180 luaD_pcall + 68
12  liblua.5.1.dylib                      0x10f49464f luaD_rawrunprotected + 84
11  liblua.5.1.dylib                      0x10f494f08 luaD_call + 80
10  liblua.5.1.dylib                      0x10f494ab6 luaD_precall + 455
9   libmpv.1.dylib                        0x110ff6f53 load_scripts + 291
8   liblua.5.1.dylib                      0x10f491550 lua_call + 41
7   liblua.5.1.dylib                      0x10f494f19 luaD_call + 97
6   liblua.5.1.dylib                      0x10f49e10c luaV_execute + 3514
5   liblua.5.1.dylib                      0x10f494ab6 luaD_precall + 455
4   libmpv.1.dylib                        0x110ff7fcd script_get_property_native + 141
3   libmpv.1.dylib                        0x110ff8e04 mp_lua_PITA + 132
2   libmpv.1.dylib                        0x11105cf7d ta_new_context + 13
1   libmpv.1.dylib                        0x11105c143 ta_alloc_size + 35
0   libsystem_malloc.dylib             0x7fff20163061 _malloc_zone_malloc + 242 
====
    24 (1.69K) << TOTAL >>
      ----
      2 (144 bytes) ROOT CYCLE: 0x600000254140 [64]
         1 (80 bytes) ROOT CYCLE: 0x6000034f1e50 [80]
            CYCLE BACK TO 0x600000254140 [64]
      ----
      2 (144 bytes) ROOT CYCLE: 0x60000025bb80 [64]
         1 (80 bytes) ROOT CYCLE: 0x6000034f0b90 [80]
            CYCLE BACK TO 0x60000025bb80 [64]
      ----
      2 (144 bytes) ROOT CYCLE: 0x600000d18d80 [64]
         1 (80 bytes) ROOT CYCLE: 0x6000034dc7d0 [80]
            CYCLE BACK TO 0x600000d18d80 [64]
      ----
      2 (144 bytes) ROOT CYCLE: 0x600000d18f00 [64]
         1 (80 bytes) ROOT CYCLE: 0x6000034dc910 [80]
            CYCLE BACK TO 0x600000d18f00 [64]
      ----
      2 (144 bytes) ROOT CYCLE: 0x600000d19080 [64]
         1 (80 bytes) ROOT CYCLE: 0x6000034dcaf0 [80]
            CYCLE BACK TO 0x600000d19080 [64]
      ----
      2 (144 bytes) ROOT CYCLE: 0x600000d57980 [64]
         1 (80 bytes) ROOT CYCLE: 0x6000034eafd0 [80]
            CYCLE BACK TO 0x600000d57980 [64]
      ----
      2 (144 bytes) ROOT CYCLE: 0x600000d5cbc0 [64]
         1 (80 bytes) ROOT CYCLE: 0x6000034e9ef0 [80]
            CYCLE BACK TO 0x600000d5cbc0 [64]
      ----
      2 (144 bytes) ROOT CYCLE: 0x600000d5ccc0 [64]
         1 (80 bytes) ROOT CYCLE: 0x6000034e9f40 [80]
            CYCLE BACK TO 0x600000d5ccc0 [64]
      ----
      2 (144 bytes) ROOT CYCLE: 0x600000d5dbc0 [64]
         1 (80 bytes) ROOT CYCLE: 0x6000034d6da0 [80]
            CYCLE BACK TO 0x600000d5dbc0 [64]
      ----
      2 (144 bytes) ROOT CYCLE: 0x600000d5dcc0 [64]
         1 (80 bytes) ROOT CYCLE: 0x6000034d6c10 [80]
            CYCLE BACK TO 0x600000d5dcc0 [64]
      ----
      2 (144 bytes) ROOT CYCLE: 0x600000d5ddc0 [64]
         1 (80 bytes) ROOT CYCLE: 0x6000034d6df0 [80]
            CYCLE BACK TO 0x600000d5ddc0 [64]
      ----
      2 (144 bytes) ROOT CYCLE: 0x600000d5df40 [64]
         1 (80 bytes) ROOT CYCLE: 0x6000034d6b70 [80]
            CYCLE BACK TO 0x600000d5df40 [64]

I was not able to reproduce this leak running mpv 0.31.1, the latest mpv release as of this writing. Checking git history shows there have been numerous changes to the mpv source lua.c since mpv 0.32.0 was released in January 2020: History for mpv / player / lua.c

This includes changes to memory allocation and the mp_lua_PITA method listed in the leaks output : lua: use an autofree wrapper instead of mp_lua_PITA

It seems likely this leak will be fixed when IINA upgrades to a newer verison of mpv.

Steps to reproduce:

Run IINA, open a video, run leaks against IINA.

  • MPV does not have this problem.

I believe this is a problem in mpv 0.32.0 that has been fixed in mpv 0.33.1.

How often does this happen?

Every time

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions