roc-lang / roc

A fast, friendly, functional language.
https://roc-lang.org
Universal Permissive License v1.0
4.13k stars 290 forks source link

Memory corruption errors since updating to basic-cli 0.15.0 #7083

Open imclerran opened 4 days ago

imclerran commented 4 days ago

Since updating roc-start to basic-cli v0.15.0 (major jump from v0.10.0), roc-start now consistently crashes with various memory corruption errors when running the update logic.

The error seems to take many different forms, but always in the update logic for roc-start. Often it will crash immediately after the first update (platforms), but may also crash during/after the package update (haven't observed an app-stub crash yet - this logic is different). It may also successfully update (no crashes in any stage of the updates), but if it does, then when the TUI menu is reached, either the last item in the platforms menu list will be corrupted, or the program will crash when progressing from app name input to platform selection.

In the case of the TUI crash (example 6), the carriage return becomes broken in the current terminal instance, and any time that a newline is printed, the carriage does not return.

It should be noted that the local files which store the platforms/packages do not get corrupted in any of these cases, and if the app is re-run without the update flag, all platforms, etc will list correctly, including newly downloaded items.

Error forms encountered:

1) ### Heap corruption

user@Users-MacBook-Air src [update-platform] $ ./main tui -u
Updating platform repository... ✔
main(90547,0x16b393000) malloc: Heap corruption detected, free list is damaged at 0x600000a4bc80
*** Incorrect guard value: 8711284952
main(90547,0x16b393000) malloc: *** set a breakpoint in malloc_error_break to debug
zsh: abort      ./main tui -u

2) ### Non-alligned pointer being freed

user@Users-MacBook-Air src [update-platform] $ ./main update
Updating platform repository... ✔
main(95023,0x2073b8f40) malloc: Non-aligned pointer 0x6000005332c0 being freed (2)
main(95023,0x2073b8f40) malloc: *** set a breakpoint in malloc_error_break to debug
zsh: abort      ./main update

3) ### Segfault

user@Users-MacBook-Air src [main] $ ./main update
Updating platform repository... ✔
zsh: segmentation fault  ./main tui -u

4) ### Internal invariant broken (next ptr of prev)

user@Users-MacBook-Air src [main] $ ./main update
Updating platform repository... ✔
Updating package repository... roc_app_binary(80508,0x16d863000) malloc: tiny_free_list_remove_ptr: Internal invariant broken (next ptr of prev): ptr=0x12561c640, prev_next=0x12561c64000
roc_app_binary(80508,0x16d863000) malloc: *** set a breakpoint in malloc_error_break to debug

5) ### Pointer being freed was not allocated

user@Users-MacBook-Air src [main] $ ./main update
Updating platform repository... ✔
roc_app_binary(78890,0x16b4e7000) malloc: *** error for object 0x600000fa4fc0: pointer being freed was not allocated
roc_app_binary(78890,0x16b4e7000) malloc: *** set a breakpoint in malloc_error_break to debug

6) ### Double free when progressing from app name input to platform selection

└─ ENTER : CONFIRM | BKSP : GO BACK ──────────main(89919,0x2073b8f40) malloc: Double free of object 0x101506de0
                                                                main(89919,0x2073b8f40) malloc: *** set a breakpoint in malloc_error_break to debug
      zsh: abort      ./main tui -u
                                   % 

7) ### Corrupt string for last platform in the list (with roc-turtle added to platform list, roc-turtle is now corrupted)

╒════════════════════════════════════════════════ Ctrl+C : QUIT ═╕
│ SELECT A PLATFORM:                                             │
│ > basic-cli                                                    │
│ - basic-ssg                                                    │
│ - basic-webserver                                              │
| -    &                                                         |
└─ ENTER : SELECT | S : SEARCH | BKSP : GO BACK ─────────────────┘
Anton-4 commented 3 days ago

Just linking to the zulip discussion https://roc.zulipchat.com/#narrow/stream/231634-beginners/topic/Memory.20corruption.20errors.20since.20updating.20to.20basic-cli.200.2E15.2E0/near/469766323