Menu

#1106 Memory leaks in c1541

v3.3
closed-fixed
compyx
None
SDL2x
c1541
2023-08-28
2019-02-28
No
  • VICE 3.3
  • compiled from source under macos 10.11.6

Given the following command:

$ c1541 -format speed-test,00 d64 speed-test.d64

returns the following memleak warnings:

formatting in unit 8 ...

archdep_join_paths.c:80: Warning: Memory block(s) allocated here was not free'd (Memory leak with size 0x1d at 0x7fcf72003200).
callstack:
              1   c1541                               0x0000000105e43f25 lib_calloc_pinpoint + 469
               2   c1541                               0x0000000105e4c230 archdep_join_paths + 272
                3   c1541                               0x0000000105e4c95d archdep_user_config_path + 45
                 4   c1541                               0x0000000105e4ba0f archdep_create_user_config_dir + 15
                  5   c1541                               0x0000000105e4b873 archdep_init + 19
                   6   c1541                               0x0000000105e3e057 main + 55
                    7   libdyld.dylib                       0x00007fff943aa5ad start + 1
                     8   ???                                 0x0000000000000005 0x0 + 5


Total memory leaks: 1 in 1 lines. Total bytes leaked: 0x1d (29B).

max. total memory that was allocated: 0xaab9 bytes. (42KiB)

Top 50 largest allocated blocks:
    2458 bytes (9KiB) allocated at c1541.c:4749
    2458 bytes (9KiB) allocated at c1541.c:4749
    2458 bytes (9KiB) allocated at c1541.c:4749
    2458 bytes (9KiB) allocated at c1541.c:4749
    15c8 bytes (5KiB) allocated at c1541.c:1076
     100 bytes (256B) allocated at vdrive.c:101
     100 bytes (256B) allocated at vdrive.c:317
      80 bytes (128B) allocated at ioutil.c:204
      50 bytes (80B) allocated at zfile.c:165
      48 bytes (72B) allocated at util.c:85
      30 bytes (48B) allocated at fsimage-create.c:381
      30 bytes (48B) allocated at diskimage.c:468
      20 bytes (32B) allocated at fsimage-create.c:382
      20 bytes (32B) allocated at fsimage.c:105
      1d bytes (29B) allocated at archdep_join_paths.c:80
      18 bytes (24B) allocated at archdep_join_paths.c:80
      18 bytes (24B) allocated at archdep_join_paths.c:80
      18 bytes (24B) allocated at log.c:238
      10 bytes (16B) allocated at archdep_home_path.c:111
      10 bytes (16B) allocated at log.c:238
      10 bytes (16B) allocated at util.c:85
      10 bytes (16B) allocated at vdrive-command.c:109
      10 bytes (16B) allocated at cbmdos.c:158
       f bytes (15B) allocated at fsimage-create.c:388
       f bytes (15B) allocated at fsimage.c:61
       f bytes (15B) allocated at util.c:594
       c bytes (12B) allocated at log.c:241
       b bytes (11B) allocated at vdrive-command.c:983
       8 bytes (8B) allocated at log.c:238
       8 bytes (8B) allocated at log.c:241
       6 bytes (6B) allocated at log.c:241

Discussion

  • compyx

    compyx - 2019-02-28

    I cannot reproduce this on either Linux or Windows with current trunk. Which 3.3 did you use? The 3.3 tarball, or current trunk?

     
  • Silver Dream !

    Silver Dream ! - 2019-02-28

    3.3 as released - the tarball. Also, AFAIR you need to add configure flags to enable these messages. --enable-debug AFAIR.

     
  • compyx

    compyx - 2019-02-28
    • status: open --> pending-fixed
    • assigned_to: compyx
    • Port: --> SDL2x
     
  • compyx

    compyx - 2019-02-28

    Fixed in r36101. The leak was in SDL's archdep_shutdown(), while I was staring myself blind on the Gtk archdep code. Probably should have asked which UI you were using :)

    Anyway, the fix is a one-liner: add archdep_user_config_path_free() to src/arch/sdl/archdep.c inside archdep_shutdown() if you want to fix the bug in the 3.3 source.

     
  • Silver Dream !

    Silver Dream ! - 2019-02-28

    Heh - yeah - didn't think about the UI either. Otherwise I'd state it in the original description. Thanks for the fix and yes, I'll apply it to my sources.

     
  • compyx

    compyx - 2019-02-28

    Cool. Let me know if that fix works, then I can close this.

    And thanks for reporting the bug.

     
  • Silver Dream !

    Silver Dream ! - 2019-02-28

    I added the line in question at the end of the said function and yes, it seems to have fixed the c1541 leakage. OTOH I just noticed that the emulator(s) themselves generate lots of leaks. It would be good to check them too. An example running x64sc:

    mon_lex.l:562: Warning: Memory block(s) allocated here was not free'd (Memory leak with size 0x15e at 0x7fb77a8e5800).
    callstack:
                  1   x64sc                               0x000000010a0397d5 lib_stralloc_pinpoint + 181
                   2   x64sc                               0x000000010a175dfc yylex + 13340
                    3   x64sc                               0x000000010a166737 yyparse + 679
                     4   x64sc                               0x000000010a169698 parse_and_execute_line + 136
                      5   x64sc                               0x000000010a179444 playback_commands + 212
                       6   x64sc                               0x000000010a056dce machine_specific_init + 478
                        7   x64sc                               0x000000010a031db0 init_main + 80
                         8   x64sc                               0x000000010a03b91b main_program + 1323
                          9   libdyld.dylib                       0x00007fff943aa5ad start + 1
    
    mon_lex.l:532: Warning: Memory block(s) allocated here was not free'd (Memory leak with size 0x1903 at 0x7fb77a8e7a00).
    callstack:
                  1   x64sc                               0x000000010a0397d5 lib_stralloc_pinpoint + 181
                   2   x64sc                               0x000000010a174220 yylex + 6208
                    3   x64sc                               0x000000010a166737 yyparse + 679
                     4   x64sc                               0x000000010a169698 parse_and_execute_line + 136
                      5   x64sc                               0x000000010a179444 playback_commands + 212
                       6   x64sc                               0x000000010a056dce machine_specific_init + 478
                        7   x64sc                               0x000000010a031db0 init_main + 80
                         8   x64sc                               0x000000010a03b91b main_program + 1323
                          9   libdyld.dylib                       0x00007fff943aa5ad start + 1
    
    monitor.c:1670: Warning: Memory block(s) allocated here was not free'd (Memory leak with size 0x1fb0 at 0x7fb77a8e9c00).
    callstack:
                  1   x64sc                               0x000000010a03941e lib_malloc_pinpoint + 94
                   2   x64sc                               0x000000010a17a149 mon_add_name_to_symbol_table + 409
                    3   x64sc                               0x000000010a167282 yyparse + 3570
                     4   x64sc                               0x000000010a169698 parse_and_execute_line + 136
                      5   x64sc                               0x000000010a179444 playback_commands + 212
                       6   x64sc                               0x000000010a056dce machine_specific_init + 478
                        7   x64sc                               0x000000010a031db0 init_main + 80
                         8   x64sc                               0x000000010a03b91b main_program + 1323
                          9   libdyld.dylib                       0x00007fff943aa5ad start + 1
    
    monitor.c:1678: Warning: Memory block(s) allocated here was not free'd (Memory leak with size 0x1fb0 at 0x7fb77a8ebe00).
    callstack:
                  1   x64sc                               0x000000010a03941e lib_malloc_pinpoint + 94
                   2   x64sc                               0x000000010a17a187 mon_add_name_to_symbol_table + 471
                    3   x64sc                               0x000000010a167282 yyparse + 3570
                     4   x64sc                               0x000000010a169698 parse_and_execute_line + 136
                      5   x64sc                               0x000000010a179444 playback_commands + 212
                       6   x64sc                               0x000000010a056dce machine_specific_init + 478
                        7   x64sc                               0x000000010a031db0 init_main + 80
                         8   x64sc                               0x000000010a03b91b main_program + 1323
                          9   libdyld.dylib                       0x00007fff943aa5ad start + 1
    
    mon_util.c:98: Warning: Memory block(s) allocated here was not free'd (Memory leak with size 0x2711 at 0x7fb77a901200).
    callstack:
                  1   x64sc                               0x000000010a03941e lib_malloc_pinpoint + 94
                   2   x64sc                               0x000000010a172465 mon_out + 261
                    3   x64sc                               0x000000010a17a101 mon_add_name_to_symbol_table + 337
                     4   x64sc                               0x000000010a167282 yyparse + 3570
                      5   x64sc                               0x000000010a169698 parse_and_execute_line + 136
                       6   x64sc                               0x000000010a179444 playback_commands + 212
                        7   x64sc                               0x000000010a056dce machine_specific_init + 478
                         8   x64sc                               0x000000010a031db0 init_main + 80
                          9   x64sc                               0x000000010a03b91b main_program + 1323
                           10  libdyld.dylib                       0x00007fff943aa5ad start + 1
    
    mon_lex.l:564: Warning: Memory block(s) allocated here was not free'd (Memory leak with size 0xe0 at 0x7fb77a064600).
    callstack:
                  1   x64sc                               0x000000010a0397d5 lib_stralloc_pinpoint + 181
                   2   x64sc                               0x000000010a175e39 yylex + 13401
                    3   x64sc                               0x000000010a166737 yyparse + 679
                     4   x64sc                               0x000000010a169698 parse_and_execute_line + 136
                      5   x64sc                               0x000000010a179444 playback_commands + 212
                       6   x64sc                               0x000000010a056dce machine_specific_init + 478
                        7   x64sc                               0x000000010a031db0 init_main + 80
                         8   x64sc                               0x000000010a03b91b main_program + 1323
                          9   libdyld.dylib                       0x00007fff943aa5ad start + 1
    
    
    Total memory leaks: 1097 in 6 lines. Total bytes leaked: 0x81b2 (32KiB).
    

    If you choose so, I might add another ticket of course.

     
  • compyx

    compyx - 2019-02-28

    I think all those leaks were plugged in current trunk. I don't get any of them in either Linux or Windows. And Linux uses the same codepath as MacOS (at least as far as I know).

    But if you feel adventurous, you could try checking out trunk and compiling from that to see if the leaks are still there :)

     
  • Silver Dream !

    Silver Dream ! - 2019-02-28

    I'll compile the current trunk and let you know here. Probably tomorrow.

     
  • Silver Dream !

    Silver Dream ! - 2019-03-01

    Checked out (with many problems - sf sucks all the time) and compiled the repo version. It's still leaky:

    mon_lex.l:562: Warning: Memory block(s) allocated here was not free'd (Memory leak with size 0x15e at 0x7ff4a7249c00).
    callstack:
                  1   x64sc                               0x00000001057612f7 lib_strdup_pinpoint + 151
                   2   x64sc                               0x0000000105897db0 yylex + 11040
                    3   x64sc                               0x0000000105889749 yyparse + 633
                     4   x64sc                               0x000000010588c548 parse_and_execute_line + 136
                      5   x64sc                               0x000000010589b9b4 playback_commands + 212
                       6   x64sc                               0x000000010577dc9e machine_specific_init + 478
                        7   x64sc                               0x0000000105759c20 init_main + 80
                         8   x64sc                               0x00000001057633d2 main_program + 1330
                          9   libdyld.dylib                       0x00007fff943aa5ad start + 1
    
    mon_lex.l:532: Warning: Memory block(s) allocated here was not free'd (Memory leak with size 0x1903 at 0x7ff4a724be00).
    callstack:
                  1   x64sc                               0x00000001057612f7 lib_strdup_pinpoint + 151
                   2   x64sc                               0x0000000105897c39 yylex + 10665
                    3   x64sc                               0x0000000105889749 yyparse + 633
                     4   x64sc                               0x000000010588c548 parse_and_execute_line + 136
                      5   x64sc                               0x000000010589b9b4 playback_commands + 212
                       6   x64sc                               0x000000010577dc9e machine_specific_init + 478
                        7   x64sc                               0x0000000105759c20 init_main + 80
                         8   x64sc                               0x00000001057633d2 main_program + 1330
                          9   libdyld.dylib                       0x00007fff943aa5ad start + 1
    
    monitor.c:1666: Warning: Memory block(s) allocated here was not free'd (Memory leak with size 0x1fb0 at 0x7ff4a724e000).
    callstack:
                  1   x64sc                               0x00000001057610f3 lib_malloc_pinpoint + 67
                   2   x64sc                               0x000000010589c5c9 mon_add_name_to_symbol_table + 409
                    3   x64sc                               0x000000010588a24b yyparse + 3451
                     4   x64sc                               0x000000010588c548 parse_and_execute_line + 136
                      5   x64sc                               0x000000010589b9b4 playback_commands + 212
                       6   x64sc                               0x000000010577dc9e machine_specific_init + 478
                        7   x64sc                               0x0000000105759c20 init_main + 80
                         8   x64sc                               0x00000001057633d2 main_program + 1330
                          9   libdyld.dylib                       0x00007fff943aa5ad start + 1
    
    monitor.c:1674: Warning: Memory block(s) allocated here was not free'd (Memory leak with size 0x1fb0 at 0x7ff4a7250200).
    callstack:
                  1   x64sc                               0x00000001057610f3 lib_malloc_pinpoint + 67
                   2   x64sc                               0x000000010589c607 mon_add_name_to_symbol_table + 471
                    3   x64sc                               0x000000010588a24b yyparse + 3451
                     4   x64sc                               0x000000010588c548 parse_and_execute_line + 136
                      5   x64sc                               0x000000010589b9b4 playback_commands + 212
                       6   x64sc                               0x000000010577dc9e machine_specific_init + 478
                        7   x64sc                               0x0000000105759c20 init_main + 80
                         8   x64sc                               0x00000001057633d2 main_program + 1330
                          9   libdyld.dylib                       0x00007fff943aa5ad start + 1
    
    mon_util.c:98: Warning: Memory block(s) allocated here was not free'd (Memory leak with size 0x2711 at 0x7ff4a7265600).
    callstack:
                  1   x64sc                               0x00000001057610f3 lib_malloc_pinpoint + 67
                   2   x64sc                               0x0000000105894d15 mon_out + 261
                    3   x64sc                               0x000000010589c581 mon_add_name_to_symbol_table + 337
                     4   x64sc                               0x000000010588a24b yyparse + 3451
                      5   x64sc                               0x000000010588c548 parse_and_execute_line + 136
                       6   x64sc                               0x000000010589b9b4 playback_commands + 212
                        7   x64sc                               0x000000010577dc9e machine_specific_init + 478
                         8   x64sc                               0x0000000105759c20 init_main + 80
                          9   x64sc                               0x00000001057633d2 main_program + 1330
                           10  libdyld.dylib                       0x00007fff943aa5ad start + 1
    
    mon_lex.l:564: Warning: Memory block(s) allocated here was not free'd (Memory leak with size 0xe0 at 0x7ff4a51cd200).
    callstack:
                  1   x64sc                               0x00000001057612f7 lib_strdup_pinpoint + 151
                   2   x64sc                               0x0000000105897ded yylex + 11101
                    3   x64sc                               0x0000000105889749 yyparse + 633
                     4   x64sc                               0x000000010588c548 parse_and_execute_line + 136
                      5   x64sc                               0x000000010589b9b4 playback_commands + 212
                       6   x64sc                               0x000000010577dc9e machine_specific_init + 478
                        7   x64sc                               0x0000000105759c20 init_main + 80
                         8   x64sc                               0x00000001057633d2 main_program + 1330
                          9   libdyld.dylib                       0x00007fff943aa5ad start + 1
    
    
    Total memory leaks: 1097 in 6 lines. Total bytes leaked: 0x81b2 (32KiB).
    
     
  • compyx

    compyx - 2019-03-02

    Hmm, when I trigger the monitor. and do the following:

    a 1000 lda #$00
    sta $d020
    sta $d021
    rts
    <enter>
    exit
    

    I get 6 leaks in 3 lines, one in uimenu.c and the rest in mon_lex.l when using the SDL port, I get 40 leaks in 4 lines using the Gtk3 port and the VTE monitor, this time in uimenu.c (I know about this one: somehow Gtk doesn't clean up the GClosure instances), uimon.c and a few in mon_lex.l again.

    1097 leaks seems excessive, are you using -moncommands or so?

     
  • Silver Dream !

    Silver Dream ! - 2019-03-02

    Yes, moncommands is used in this case. It loads the labels.

     
  • compyx

    compyx - 2019-03-03

    I can see where the leaks happen, but it won't be easy to fix. Looks like actually freeing memory was only an afterthought.

     
  • compyx

    compyx - 2023-08-28

    I'm closing this bug since the original issue was fixed a long time ago. I've opened a new bug about the leaks in the monitor: bug #1936.

     
  • compyx

    compyx - 2023-08-28
    • status: pending-fixed --> closed-fixed
     

Log in to post a comment.

MongoDB Logo MongoDB