milkytracker / MilkyTracker

An FT2 compatible music tracker
http://milkytracker.github.io/
Other
1.67k stars 160 forks source link

free(): double free detected in tcache 2 #316

Closed OPNA2608 closed 1 year ago

OPNA2608 commented 1 year ago

1.04.00 crashes immediately after finishing the splash screen.

Available Renderers: opengl opengles2 opengles software 
Vendor     : AMD
Renderer   : AMD Radeon RX 5700 XT (navi10, LLVM 15.0.7, DRM 3.49, 6.1.35-xanmod1)
Version    : OpenGL ES 3.2 Mesa 23.0.3
SDL: Minimum window size set to 640x480.
[New Thread 0x7fffe8bc76c0 (LWP 32936)]
SDL: Using accelerated renderer.
SDL: Renderer supports rendering to texture.
0 0
[New Thread 0x7fffd30ac6c0 (LWP 32938)]
[New Thread 0x7fffd306b6c0 (LWP 32939)]
SDL: Using audio driver: pulseaudio
SDL: Buffer size = 2048 samples (requested 2048)
MIDI: scanning input ports:
MIDI:  0. Midi Through:Midi Through Port-0 14:0
free(): double free detected in tcache 2

Thread 1 "milkytracker" received signal SIGABRT, Aborted.
0x00007ffff76a1a8c in __pthread_kill_implementation () from /nix/store/3n58xw4373jp0ljirf06d8077j15pc4j-glibc-2.37-8/lib/libc.so.6
(gdb) bt
#0  0x00007ffff76a1a8c in __pthread_kill_implementation () from /nix/store/3n58xw4373jp0ljirf06d8077j15pc4j-glibc-2.37-8/lib/libc.so.6
#1  0x00007ffff7652c86 in raise () from /nix/store/3n58xw4373jp0ljirf06d8077j15pc4j-glibc-2.37-8/lib/libc.so.6
#2  0x00007ffff763c8ba in abort () from /nix/store/3n58xw4373jp0ljirf06d8077j15pc4j-glibc-2.37-8/lib/libc.so.6
#3  0x00007ffff763d5f5 in __libc_message.cold () from /nix/store/3n58xw4373jp0ljirf06d8077j15pc4j-glibc-2.37-8/lib/libc.so.6
#4  0x00007ffff76ab735 in malloc_printerr () from /nix/store/3n58xw4373jp0ljirf06d8077j15pc4j-glibc-2.37-8/lib/libc.so.6
#5  0x00007ffff76ad9d6 in _int_free () from /nix/store/3n58xw4373jp0ljirf06d8077j15pc4j-glibc-2.37-8/lib/libc.so.6
#6  0x00007ffff76afe53 in free () from /nix/store/3n58xw4373jp0ljirf06d8077j15pc4j-glibc-2.37-8/lib/libc.so.6
#7  0x0000000000410bc0 in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string (this=0x7fffffffa1b0, __in_chrg=<optimized out>) at /nix/store/6vwsydq4nzr1l8j7fyg5r61nknwq6w60-gcc-12.3.0/include/c++/12.3.0/bits/basic_string.h:802
#8  MidiReceiver::countPorts (this=this@entry=0x134bd60) at /build/source/src/midi/posix/MidiReceiver_pthread.cpp:139
#9  0x000000000052f264 in MidiReceiver::MidiReceiver (this=this@entry=0x134bd60, midiEventHandler=...) at /build/source/src/midi/posix/MidiReceiver_pthread.cpp:45
#10 0x00000000004b009e in StartMidiRecording (devID=0) at /build/source/src/tracker/sdl/SDL_Main.cpp:275
#11 0x00000000004b012c in InitMidi () at /build/source/src/tracker/sdl/SDL_Main.cpp:287
#12 0x00000000004b1408 in initTracker (bpp=bpp@entry=4294967295, orientation=orientation@entry=PPDisplayDevice::ORIENTATION_NORMAL, swapRedBlue=swapRedBlue@entry=false, noSplash=noSplash@entry=false) at /build/source/src/tracker/sdl/SDL_Main.cpp:835
#13 0x0000000000411235 in main (argc=<optimized out>, argv=<optimized out>) at /build/source/src/tracker/sdl/SDL_Main.cpp:969
Thread 1 "milkytracker" hit Breakpoint 1, MidiReceiver::countPorts (this=this@entry=0x13482a0) at /build/source/src/midi/posix/MidiReceiver_pthread.cpp:138
138 {
(gdb) n
139     midiin = new RtMidiIn();
(gdb) 
140     unsigned int nPorts = midiin->getPortCount();
(gdb) 
141     std::cout << "MIDI: scanning input ports:\n";
(gdb) 
MIDI: scanning input ports:
142     for ( unsigned i=0; i<nPorts; i++ ) {
(gdb) 
143         std::string portName = midiin->getPortName(i);
(gdb) 
144         std::cout << "MIDI:  " << i << ". " << portName << '\n';
(gdb) 
MIDI:  0. Midi Through:Midi Through Port-0 14:0
145     }
(gdb) 
142     for ( unsigned i=0; i<nPorts; i++ ) {
(gdb) 
146     delete midiin;
(gdb) 
147     midiin = NULL;
(gdb) 
139     midiin = new RtMidiIn();
(gdb) 
free(): double free detected in tcache 2
coderofsalvation commented 1 year ago

Hi OPNA, thank you for this. What architecture/distro version are you running?

OPNA2608 commented 1 year ago

x86_64, NixOS 23.05. Trying to bump our package to the new version :slightly_smiling_face:

OPNA2608 commented 1 year ago

Duplicate: https://github.com/milkytracker/MilkyTracker/issues/318

/build/source/src/midi/posix/MidiReceiver_pthread.cpp: In member function 'unsigned int MidiReceiver::countPorts()':
/build/source/src/midi/posix/MidiReceiver_pthread.cpp:148:1: warning: no return statement in function returning non-void [8;;https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wreturn-type-Wreturn-type8;;]
  148 | }
      | ^

I guess the lack of a return is breaking stuff. Shouldn't that method return nPorts?

coderofsalvation commented 1 year ago

I've committed a fix to master. Does it work now?

OPNA2608 commented 1 year ago

Think it works for me now, I'll close when I can confirm on the system that I originally had the issue with.

OPNA2608 commented 1 year ago

Yep works fine now, thanks!