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: error pointer being freed was not allocated #1877

Closed
6 of 9 tasks
XhstormR opened this issue May 5, 2024 · 9 comments
Closed
6 of 9 tasks

malloc: error pointer being freed was not allocated #1877

XhstormR opened this issue May 5, 2024 · 9 comments
Labels

Comments

@XhstormR
Copy link

XhstormR commented May 5, 2024

Environment details (Put x in the checkbox along with the information)

  • Operating System: MacOS
  • Desktop Environment: Darwin 23.4.0 x86_64 i386
  • Terminal Emulator: alacritty
  • Shell: fishshell, version 3.7.1
  • Custom desktop opener (if applicable):
  • Program options used: -adexoiUH -Te -Pp
  • Configuration options set:
  • Plugins are installed: export NNN_PLUG='p:preview-tui;o:fzopen;c:fzcd;z:autojump;x:!chmod +x $nnn*;'
  • Issue exists on nnn master

Exact steps to reproduce the issue

nnn 4.9 installed from brew, after pressing n to enter nnn, directly enter ? for help, then enter q to exit help, and then press q again to exit nnn, and then an exception will occur.

Exception log:

        Alt ;  Select plugin           =  Launch app
         ! ^]  Shell                   ]  Cmd prompt
nnn(53031,0x7ff84ee82100) malloc: *** error for object 0x2020202020202020: pointer being freed was not allocated
nnn(53031,0x7ff84ee82100) malloc: *** set a breakpoint in malloc_error_break to debug
fish: Job 1, 'command nnn $argv' terminated by signal SIGABRT (Abort)
⏎
image
@XhstormR XhstormR added the bug label May 5, 2024
@jarun
Copy link
Owner

jarun commented May 5, 2024

I am unable to reproduce on Ubuntu. Can you please debug further to figure out which pointer is being freed without allocation?

@jarun
Copy link
Owner

jarun commented May 5, 2024

This is coming from commit 3665541 and the next one.

@N-R-K can you please have a look?

@jarun
Copy link
Owner

jarun commented May 5, 2024

Can we write directly to fd instead of having the temporary buffer?

@jarun jarun closed this as completed in be6988d May 5, 2024
@jarun
Copy link
Owner

jarun commented May 5, 2024

Please confirm that the fix works.

@N-R-K
Copy link
Collaborator

N-R-K commented May 5, 2024

This looks like a duplicate of #1768

It should be fixed in master. @XhstormR Can you try master branch and confirm?

This is coming from commit 3665541 and the next one.

@jarun I'm pretty sure that that is the commit that fixed the issue. be6988d should not be necessary.

@N-R-K
Copy link
Collaborator

N-R-K commented May 5, 2024

Can we write directly to fd instead of having the temporary buffer?

Making a syscall for each and every byte seems unnecessary waste of resources to me.

IMO be6988d should be reverted since the bug was already fixed.

OP was using v4.9 instead of master branch. Maybe we can cut a new release soon?

@jarun
Copy link
Owner

jarun commented May 6, 2024

I reproduced this one master (using fastmac) before attempting the fix.

As for a syscall overhead, I will add a new version to use dprintf.

@N-R-K
Copy link
Collaborator

N-R-K commented May 7, 2024

I reproduced this one master (using fastmac) before attempting the fix.

Interesting. I don't know how that's possible. The help string is 1832 bytes and the buffer is 2048 bytes. It has more than enough space.

As for a syscall overhead, I will add a new version to use dprintf.

dprintf also makes 1 write syscall per call since dprintf uses file-descriptor directly without any buffering.

You'd need to use a FILE * with fopen + fwrite etc to avoid many syscalls. Do you want to make that change yourself or should I open a PR later today?

@jarun
Copy link
Owner

jarun commented May 7, 2024

Please raise the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants