From e84ec2978a988f2e760a70de1b7bdd6181109f95 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 21 Feb 2018 21:33:56 +0100 Subject: [PATCH] - plugged the pending memory leaks. --- .../music_timiditypp_mididevice.cpp | 6 ++++- src/sound/timiditypp/instrum.cpp | 6 ++--- src/sound/timiditypp/instrum.h | 1 + src/sound/timiditypp/playmidi.cpp | 22 ++++++------------- src/sound/timiditypp/playmidi.h | 4 ---- 5 files changed, 15 insertions(+), 24 deletions(-) diff --git a/src/sound/mididevices/music_timiditypp_mididevice.cpp b/src/sound/mididevices/music_timiditypp_mididevice.cpp index dd288c71be..fb2be1aed1 100644 --- a/src/sound/mididevices/music_timiditypp_mididevice.cpp +++ b/src/sound/mididevices/music_timiditypp_mididevice.cpp @@ -118,8 +118,12 @@ TimidityPPMIDIDevice::TimidityPPMIDIDevice(const char *args) if (instruments != nullptr && !instruments->checkConfig(args)) { delete instruments; + instruments = nullptr; + } + if (instruments == nullptr) + { + instruments = new TimidityPlus::Instruments; } - instruments = new TimidityPlus::Instruments; if (!instruments->load(args)) { delete instruments; diff --git a/src/sound/timiditypp/instrum.cpp b/src/sound/timiditypp/instrum.cpp index 5d47a460dc..b73825ff56 100644 --- a/src/sound/timiditypp/instrum.cpp +++ b/src/sound/timiditypp/instrum.cpp @@ -1867,15 +1867,13 @@ Instrument *Instruments::play_midi_load_instrument(int dr, int bk, int prog, boo void Instruments::init_userdrum() { int i; - AlternateAssign *alt; free_userdrum(); for (i = 0; i<2; i++) { /* allocate alternative assign */ - alt = (AlternateAssign *)safe_malloc(sizeof(AlternateAssign)); - memset(alt, 0, sizeof(AlternateAssign)); + memset(&alt[i], 0, sizeof(AlternateAssign)); alloc_instrument_bank(1, 64 + i); - drumset[64 + i]->alt = alt; + drumset[64 + i]->alt = &alt[i]; } } diff --git a/src/sound/timiditypp/instrum.h b/src/sound/timiditypp/instrum.h index b2be8f30cc..1894e08fe7 100644 --- a/src/sound/timiditypp/instrum.h +++ b/src/sound/timiditypp/instrum.h @@ -319,6 +319,7 @@ class Instruments UserDrumset *userdrum_first = (UserDrumset *)NULL; UserDrumset *userdrum_last = (UserDrumset *)NULL; + AlternateAssign alt[2]; /* Some functions get aggravated if not even the standard banks are available. */ ToneBank diff --git a/src/sound/timiditypp/playmidi.cpp b/src/sound/timiditypp/playmidi.cpp index c50e7ed97a..5f49fdc93c 100644 --- a/src/sound/timiditypp/playmidi.cpp +++ b/src/sound/timiditypp/playmidi.cpp @@ -5779,11 +5779,6 @@ struct midi_file_info *Player::new_midi_file_info() return p; } -struct midi_file_info *Player::get_midi_file_info(const char *filename, int newp) -{ - return &midifileinfo; -} - /* @@ -5799,21 +5794,18 @@ void Player::playmidi_stream_init(void) CLEAR_CHANNELMASK(channel_mute); if (temper_type_mute & 1) FILL_CHANNELMASK(channel_mute); - if(first) - { - first = 0; - init_mblock(&playmidi_pool); - current_file_info = get_midi_file_info("TiMidity", 1); - midi_streaming=1; - } + if (first) + { + first = 0; + init_mblock(&playmidi_pool); + midi_streaming = 1; + } else reuse_mblock(&playmidi_pool); /* Fill in current_file_info */ - current_file_info = get_midi_file_info("", 0); + current_file_info = &midifileinfo; current_file_info->readflag = 1; - current_file_info->seq_name = safe_strdup("TiMidity server"); - current_file_info->karaoke_title = current_file_info->first_text = NULL; current_file_info->hdrsiz = 0; current_file_info->format = 0; current_file_info->tracks = 0; diff --git a/src/sound/timiditypp/playmidi.h b/src/sound/timiditypp/playmidi.h index 75bd350d66..6bf675fc93 100644 --- a/src/sound/timiditypp/playmidi.h +++ b/src/sound/timiditypp/playmidi.h @@ -490,9 +490,6 @@ enum { struct midi_file_info { int readflag; - char *seq_name; - char *karaoke_title; - char *first_text; int16_t hdrsiz; int16_t format; int16_t tracks; @@ -723,7 +720,6 @@ public: void free_drum_effect(int); void change_system_mode(int mode); - struct midi_file_info *get_midi_file_info(const char *filename, int newp); void recompute_freq(int v); int get_default_mapID(int ch); void init_channel_layer(int ch);