-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Fix memory leak in MIDI export #26415 #26798
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
Conversation
Replace new unsigned char allocations with QVector<unsigned char> and make sure that MidiEvent::setEData takes vector reference rather than raw pointer. Backport of musescore#26798
Replace new unsigned char allocations with QVector<unsigned char> and make sure that MidiEvent::setEData takes vector reference rather than raw pointer. Backport of musescore#26798
Replace new unsigned char allocations with std::vector<unsigned char> and make sure that MidiEvent::setEData takes vector reference rather than raw pointer. Backport of musescore#26798
@@ -587,9 +586,8 @@ bool MidiFile::readEvent(MidiEvent* event) | |||
LOGD("readEvent: error 6"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't/Couldn't the above if
be an else if
?
if (me == 0xf0 || me == 0xf7) {
...
} else if (me == ME_META) {
...
}
if (me & 0x80) { // status byte
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Jojo-Schmitz I think you are right and that should not introduce any issues.
if (me == 0xf0 || me == 0xf7) {
// SysEx handling
...
return ..
} else if (me == ME_META) {
// Meta handling
...
return ...
}
if (me & 0x80) {
...
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to be a small optimization
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably this small optimization can go into a separate PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't see why, but maybe into a separate commit of this PR
Replace new unsigned char allocations with std::vector<unsigned char> and make sure that MidiEvent::setEData takes vector reference rather than raw pointer. Backport of musescore#26798
Replace new unsigned char allocations with std::vector<unsigned char> and make sure that MidiEvent::setEData takes vector reference rather than raw pointer. Backport of musescore#26798
Replace new unsigned char allocations with std::vector<unsigned char> and make sure that MidiEvent::setEData takes vector reference rather than raw pointer.
Make sure the vector size is properly resized before read operation and remove null termination. Avoid copy assignment by using move semantics.
04fdc89
to
05befe3
Compare
Replace new unsigned char allocations with std::vector<unsigned char> and make sure that MidiEvent::setEData takes vector reference rather than raw pointer. Backport of musescore#26798
if (dataLen) { | ||
read(data, dataLen); | ||
data.resize(dataLen + 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems the resize needs to be donw before the if
, at least in my backport I do get a crash in the unit tests otherwise, terminate called after throwing an instance of 'std::logic_error'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems the 2nd time this PR reveals an issue with the (MIDI import) unit tests vs. those from Mu3
Backport by Jojo-Schmitz showed a 'std::logic_error' when resizing data vector is inside the if-statement rather than outside the if-statement.
Replace new unsigned char allocations with std::vector<unsigned char> and make sure that MidiEvent::setEData takes vector reference rather than raw pointer. Backport of musescore#26798
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, looks good to me now!
Replace new unsigned char allocations with std::vector<unsigned char> and make sure that MidiEvent::setEData takes vector reference rather than raw pointer. Backport of musescore#26798 Co-Authored-By: Casper Jeukendrup <[email protected]> Co-Authored-By: Thomas Stibor <[email protected]>
Something for 4.5.0? |
Replace new unsigned char allocations with std::vector<unsigned char> and make sure that MidiEvent::setEData takes vector reference rather than raw pointer. Backport of musescore#26798 Co-Authored-By: Casper Jeukendrup <[email protected]> Co-Authored-By: Thomas Stibor <[email protected]>
I'm not completely sure. Maybe better not, because this seems the type of change where an oversight is easily made, so it may be better to give it some time to ripe. |
Replace new unsigned char allocations with std::vector and make sure that MidiEvent::setEData takes vector reference rather than raw pointer.
Resolves: #26415