MichaelAquilina / zsh-you-should-use

📎 ZSH plugin that reminds you to use existing aliases for commands you just typed
GNU General Public License v3.0
1.49k stars 44 forks source link

check_alias_usage results in a malloc error failing to load counting data #106

Open andrewcrook opened 4 years ago

andrewcrook commented 4 years ago

Issue Details

possible bug check_alias_usage results in a malloc error. Aliases seem to be listed, however, the counting data is always 0.

Operating System (uname -a)

macOS Catalina 10.15.6 (19G73)

Darwin Andrews-MBP.local 19.6.0 Darwin Kernel Version 19.6.0: Sun Jul 5 00:43:10 PDT 2020; root:xnu-6153.141.1~9/RELEASE_X86_64 x86_64

zsh version (zsh --version)

zsh 5.7.1 (x86_64-apple-darwin19.0)

you-should-use version (echo "$YSU_VERSION")

1.7.3

How is zsh-you-should-use installed?

Antibody

Steps to reproduce the issue

❯ ~ ❯ check_alias_usage

tail(23339,0x110ca1dc0) malloc: can't allocate region
:*** mach_vm_map(size=144000000000000000, flags: 100) failed (error code=3)
tail(23339,0x110ca1dc0) malloc: *** set a breakpoint in malloc_error_break to debug
tail: malloc: Cannot allocate memory
0: ~='cd ~'
0: z='_z 2>&1'
0: which-command='whence'
0: sc='source /Users/andrew/.zshrc'
0: run-help='man

Expected

MichaelAquilina commented 4 years ago

Thanks for reporting this issue! I actually noticed there's another regression in check_alias_usage last time so I would not be surprised if this is related.

Would you mind checking how much available free memory you had when running this?

andrewcrook commented 4 years ago

@MichaelAquilina sure top from the same shell and activity monitor. Plenty available.

> top

Processes: 411 total, 2 running, 409 sleeping, 1890 threads           13:58:49
Load Avg: 0.90, 1.19, 1.39  CPU usage: 3.49% user, 3.1% sys, 93.48% idle
SharedLibs: 307M resident, 77M data, 25M linkedit.
MemRegions: 74035 total, 5188M resident, 212M private, 2348M shared.
PhysMem: 14G used (2829M wired), 2345M unused.
VM: 2860G vsize, 1993M framework vsize, 94632(0) swapins, 168460(0) swapouts.
Networks: packets: 1925400/1744M in, 6108827/5941M out.
Disks: 999645/13G read, 345972/5090M written.

Activity Monitor

image
MTCoster commented 2 years ago

I've just encountered this (although interestingly on Monterey tail seems to be using calloc instead of malloc) - I suspect it's to do with this:

https://github.com/MichaelAquilina/zsh-you-should-use/blob/09d9aa2cad2b7caf48cce8f321ebbbf8f47ce1c3/you-should-use.plugin.zsh#L17-L20

andrewcrook commented 2 years ago

tail seems to be using calloc instead of malloc

not sure iirc the different between calloc and malloc is that calloc zeros out the memory allocation and malloc doesn’t. I suppose calloc is the slower of the two. I have since switched to bash as my main shell.