Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

malloc: attempt to free non-allocated memory (uninitialized/freed pointer/NULL) #353

Closed
jonand opened this issue Jul 4, 2019 · 15 comments
Closed

Comments

@jonand
Copy link

jonand commented Jul 4, 2019

Whenever I use hstr I get the following errors:

$ hstr
ls
hstr(45522,0x1142ce5c0) malloc: *** error for object 0x7fccffe4f40f: pointer being freed was not allocated
hstr(45522,0x1142ce5c0) malloc: *** set a breakpoint in malloc_error_break to debug
[1]    45522 abort      hstr
$ ls

It doesn't matter if I trigger it with hstr, hh or ^R, I always get the malloc errors. hstr still works, but always prints the errors
I recently re-installed my machine from scratch but the problem persists.

My config:

  • macOS Mojave v10.14.5
  • zsh 5.7.1 (x86_64-apple-darwin18.2.0)
alias hh=hstr                                # hh to be alias for hstr
export HISTFILE=~/.zhistory                  # ensure history file visibility
export HISTFILESIZE=100000                   # increase history file size
export HISTSIZE=${HISTFILESIZE}
export HSTR_CONFIG=hicolor,raw-history-view,blacklist
bindkey -s "\C-r" "\eqhstr\n"                # bind hh to Ctrl-r
@dvorka dvorka self-assigned this Sep 17, 2019
@dvorka dvorka added this to the Backlog milestone Sep 17, 2019
@dvorka dvorka modified the milestones: Backlog, 2.2 zsh stabilization Dec 11, 2019
@dvorka
Copy link
Owner

dvorka commented Dec 15, 2019

@jonand @arnas-teso @mvilanova or anybody else who can reproduce this problem, can you please share HSTR version impacted by this problem please? HSTR 2.0 was released with all memory leaks/invalid memory use fixed AFAIK. Thanks!

@arnaspet
Copy link

➜ hstr
git status
hstr(40422,0x10a0515c0) malloc: *** error for object 0x7ffdc7c8617f: pointer being freed was not allocated
hstr(40422,0x10a0515c0) malloc: *** set a breakpoint in malloc_error_break to debug
[1]    40422 abort      hstr

➜ hstr --version
hstr version "2.0.0" (2018-08-28T13:30:00)

tried upgrading with brew, but brew sees only 2.0.1 version
Warning: hstr 2.0_1 already installed

@mvilanova
Copy link

mvilanova commented Dec 16, 2019 via email

@dvorka
Copy link
Owner

dvorka commented Dec 16, 2019

@mvilanova @arnaspet thank you for quick response, it helps - I really appreciate it! 👍

@dvorka
Copy link
Owner

dvorka commented Dec 21, 2019

@mvilanova @arnaspet I just fixed a few HSTR leaks, but most probably not the one causing crash reported in this issue. It seems to be caused by freeing non-initialized/NULL pointer, but unfortunately it's not reproducible on my systems (Linux @ zsh / bash). Can you please run the following commands for and share hstr-log-*.txt files here?

strace hstr 2> hstr-log-strace.txt

and:

valgrind --track-origins=yes --tool=memcheck --leak-check=full --show-leak-kinds=all hstr 2> hstr-log-valgrind.txt

@dvorka dvorka changed the title malloc errors malloc: attempt to free non-allocated memory (uninitialized/freed pointer/NULL) Dec 21, 2019
@dvorka
Copy link
Owner

dvorka commented Dec 21, 2019

It might be fixed by e9452d2 released as HSTR 2.2, please verify.

@mvilanova
Copy link

mvilanova commented Dec 21, 2019 via email

@jonand
Copy link
Author

jonand commented Jan 7, 2020

Now 2.2 is available via brew. I installed it but I'm still seeing the malloc errors.

Unfortunately there's no strace for macOS and valgrind doesn't seem to work with macOS Catalina yet. Maybe this dtruss output helps?
sudo dtruss hstr -n &> hstr-log-dtruss.txt
hstr-log-dtruss.txt

@dvorka
Copy link
Owner

dvorka commented Jan 9, 2020

😞 thank you@jonand. I will set up macOS installation when I will be releasing my other project and try to debug it there. Thanks for patience & help!

@ostrolucky
Copy link

I was able to solve this issue by downgrading to hstr 2.0 (2.1, 2.2 have this problem in my testing)

@michael-wojcik
Copy link

I'm still seeing this same issue with 2.2 on Mac OS Catalina

@ostrolucky
Copy link

ostrolucky commented Jun 29, 2020

This is the commit that introduced this error c367541 Any C developers that can spot what's wrong with it?

❯ lldb ./src/hstr
(lldb) target create "./src/hstr"
Current executable set to '/Users/gabriel.ostrolucky/Documents/hstr/src/hstr' (x86_64).
(lldb) b malloc_error_break
Breakpoint 1: where = libsystem_malloc.dylib`malloc_error_break, address = 0x0000000000019355
(lldb) run
Process 93532 launched: '/Users/gabriel.ostrolucky/Documents/hstr/src/hstr' (x86_64)
hstr(93532,0x1000d8dc0) malloc: *** error for object 0x102a0be2f: pointer being freed was not allocated
hstr(93532,0x1000d8dc0) malloc: *** set a breakpoint in malloc_error_break to debug
Process 93532 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    frame #0: 0x00007fff68953355 libsystem_malloc.dylib`malloc_error_break
libsystem_malloc.dylib`malloc_error_break:
->  0x7fff68953355 <+0>: pushq  %rbp
    0x7fff68953356 <+1>: movq   %rsp, %rbp
    0x7fff68953359 <+4>: nop
    0x7fff6895335a <+5>: nopl   (%rax)
Target 0: (hstr) stopped.
(lldb)

@thibaultcha
Copy link
Contributor

thibaultcha commented Jul 27, 2020

Could be fixed by #410 as well. If you are experiencing this, are you using zsh by chance? Do any of the commands in your shell's history start with a colon :?

@ostrolucky
Copy link

I think you nailed it. I use zsh and there is indeed command in my history starting with :.

@dvorka
Copy link
Owner

dvorka commented Dec 3, 2021

Fixed by #410 thanks to joint work of @thibaultcha and @ostrolucky 💪 Thank you both!

@dvorka dvorka closed this as completed Dec 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants