Skip to content

Conversation

@michaelgregorius
Copy link
Contributor

Fix a memory problems that has been found by a second review of #7919 and a potential out-of-index access.

Fix problems with lifetime of QByteArray

Fix a problem with the lifetime of a QByteArray in attemptToReconnectOutput and attemptToReconnectInput (also see here: #7919 (comment)).

The method constData was called on a temporary which gets destroyed before targetName and sourceName are used, thus leading to undefined behavior.

Fix index checks

Fix index checks in attemptToReconnectOutput and attemptToReconnectInput.

The previous code would have allowed an index to be size of the underlying vector which would access out-of-bounds memory.

Fix a problem with the lifetime of a `QByteArray` in
`attemptToReconnectOutput` and `attemptToReconnectInput`.

The method `constData` was called on a temporary which gets destroyed
before `targetName` and `sourceName` are used, thus leading to undefined
behavior.
Fix index checks in `attemptToReconnectOutput` and
`attemptToReconnectInput`.

The previous code would have allowed an index to be `size` of the
underlying vector which would access out-of-bounds memory.
Add braces for one-liner if statements.
@michaelgregorius
Copy link
Contributor Author

The curly braces for the one-liner if statements have been added with commit c92c128.

In case someone wants to fix the remaining if statements without curly braces, to get them in-line with the coding conventions, you can get a list with the following grep statements in the src directory. Third party code is filtered out:

$ grep -rE '\sif.*;$' | grep -v '{' | grep -v '3rdparty'

This produces the following list as of now:

core/NotePlayHandle.cpp:        if( buffer() ) releaseBuffer();
core/ConfigManager.cpp:                         if( !success ) qWarning("Config Version conversion failure.");
core/DataFile.cpp:              if( !success ) qWarning("File Version conversion failure.");
core/BandLimitedWave.cpp:       if( s_wavesGenerated ) return;
core/Mixer.cpp:                 if( ! sendModel ) qFatal( "Error: no send model found from %d to %d", senderRoute->senderIndex(), m_channelIndex );
core/Mixer.cpp: if( sendFrom == sendTo ) return true;
core/Mixer.cpp:                         if( mxr ) mxr->amount()->loadSettings( chDataItem, "amount" );
core/DrumSynth.cpp:     // if(wave!=NULL) free(wave);
gui/widgets/LcdWidget.cpp:                      if (digit == '-') val = 11;
gui/MixerView.cpp:      if (index == 0) return;
gui/MixerView.cpp:      if (index <= 1 || index >= m_mixerChannelViews.size()) return;
gui/clips/ClipView.cpp:                         if ( min <= m_initialClipPos ) min += snapLength;
gui/clips/ClipView.cpp:                         if (min < 1) min += snapLength;
gui/clips/ClipView.cpp:                         if ( max >= m_initialClipEnd ) max -= snapLength;
gui/clips/ClipView.cpp:                         if (minLength < 1) minLength += snapLength;
gui/clips/AutomationClipView.cpp:                       if( x1 > ( width() - BORDER_WIDTH ) ) break;
gui/clips/AutomationClipView.cpp:                       if(x > (width() - BORDER_WIDTH)) break;
gui/MainWindow.cpp:             if (!export_filename.endsWith(suffix)) export_filename += suffix;
gui/FileBrowser.cpp:            if (entry.isHidden() && m_showHiddenContent && !m_showHiddenContent->isChecked()) continue;
gui/MicrotunerConfig.cpp:       m_keymapTextEdit->setToolTip(tr("Enter key mappings on separate lines. Each line assigns a scale degree to a MIDI key,\nstarting with the middle key and continuing in sequence.\nThe pattern repeats for keys outside of the explicit keymap range.\nMultiple keys can be mapped to the same scale degree.\nEnter \'x\' if you wish to leave the key disabled / not mapped."));
tracks/InstrumentTrack.cpp:     if( m_instrument ) delete m_instrument;

Files with statements like for( (no whitespace) can be found with the following command:

grep -rEl '\sfor\('

Files with statements like if( can be found with the adjusted version:

grep -rEl '\sif\('

@michaelgregorius michaelgregorius merged commit ab050b8 into LMMS:master Aug 7, 2025
11 checks passed
@michaelgregorius michaelgregorius deleted the 7919-FixMemoryProblems branch August 7, 2025 10:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants