Download raw body.
audio/lmms: Fix memory corruption during MIDI input/output
MIDI output and input are handled on different threads, so a mutex is
required to serialize access to the mio_hdl structure.
This diff fixes disconnection from sndiod caused by corruption of the
mio_hdl structure.
While we're at it, fix the input event loop to not stop if a signal is
received during poll(4). If so just recheck the m_quit flag and retry.
OK?
Index: Makefile
===================================================================
RCS file: /cvs/ports/audio/lmms/Makefile,v
diff -u -p -r1.28 Makefile
--- Makefile 5 Sep 2023 16:13:39 -0000 1.28
+++ Makefile 24 Apr 2025 13:20:42 -0000
@@ -5,7 +5,7 @@ DISTNAME = lmms_$V
PKGNAME = lmms-$V
WRKDIST = ${WRKDIR}/lmms
EXTRACT_SUFX = .tar.xz
-REVISION = 1
+REVISION = 2
CATEGORIES = audio
Index: patches/patch-include_MidiSndio_h
===================================================================
RCS file: patches/patch-include_MidiSndio_h
diff -N patches/patch-include_MidiSndio_h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ patches/patch-include_MidiSndio_h 24 Apr 2025 13:20:42 -0000
@@ -0,0 +1,19 @@
+Index: include/MidiSndio.h
+--- include/MidiSndio.h.orig
++++ include/MidiSndio.h
+@@ -32,6 +32,7 @@
+
+ #include <QtCore/QThread>
+ #include <QtCore/QFile>
++#include <QtCore/QMutex>
+
+ #include <sndio.h>
+
+@@ -64,6 +65,7 @@ class MidiSndio : public MidiClientRaw, public QThread
+ virtual void run(void);
+
+ private:
++ QMutex m_hdlMutex;
+ struct mio_hdl *m_hdl;
+ volatile bool m_quit;
+ } ;
Index: patches/patch-src_core_midi_MidiSndio_cpp
===================================================================
RCS file: patches/patch-src_core_midi_MidiSndio_cpp
diff -N patches/patch-src_core_midi_MidiSndio_cpp
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ patches/patch-src_core_midi_MidiSndio_cpp 24 Apr 2025 13:20:42 -0000
@@ -0,0 +1,48 @@
+Index: src/core/midi/MidiSndio.cpp
+--- src/core/midi/MidiSndio.cpp.orig
++++ src/core/midi/MidiSndio.cpp
+@@ -42,6 +42,7 @@
+
+ MidiSndio::MidiSndio( void ) :
+ MidiClientRaw(),
++ m_hdlMutex(),
+ m_quit( false )
+ {
+ QString dev = probeDevice();
+@@ -86,7 +87,9 @@ QString MidiSndio::probeDevice( void )
+
+ void MidiSndio::sendByte( const unsigned char c )
+ {
++ m_hdlMutex.lock();
+ mio_write( m_hdl, &c, 1 );
++ m_hdlMutex.unlock();
+ }
+
+
+@@ -99,13 +102,22 @@ void MidiSndio::run( void )
+ int ret;
+ while( m_quit == false && m_hdl )
+ {
++ m_hdlMutex.lock();
+ nfds = mio_pollfd( m_hdl, &pfd, POLLIN );
++ m_hdlMutex.unlock();
+ ret = poll( &pfd, nfds, 100 );
+- if ( ret < 0 )
++ if ( ret < 0 ) {
++ if (errno == EINTR)
++ continue;
+ break;
+- if ( !ret || !( mio_revents( m_hdl, &pfd ) & POLLIN ) )
+- continue;
+- n = mio_read( m_hdl, buf, sizeof(buf) );
++ }
++ m_hdlMutex.lock();
++ if (mio_revents( m_hdl, &pfd ) & POLLIN) {
++ n = mio_read( m_hdl, buf, sizeof(buf) );
++ } else {
++ n = 0;
++ }
++ m_hdlMutex.unlock();
+ if ( !n )
+ {
+ break;
audio/lmms: Fix memory corruption during MIDI input/output