diff --git a/libraries/music_common/fileio.h b/libraries/music_common/fileio.h index 1a26f2db4..0c592a3da 100644 --- a/libraries/music_common/fileio.h +++ b/libraries/music_common/fileio.h @@ -224,8 +224,8 @@ struct VectorReader : public MemoryReader //========================================================================== // -// The follpwing two functions are needed to allow using UTF-8 in the file interface. -// fopen on Windows is only safe for ASCII, +// The following two functions are needed to allow using UTF-8 in the file interface. +// fopen on Windows is only safe for ASCII. // //========================================================================== @@ -271,10 +271,12 @@ inline bool fileExists(const char *fn) class SoundFontReaderInterface { -public: +protected: virtual ~SoundFontReaderInterface() {} +public: virtual struct FileInterface* open_file(const char* fn) = 0; virtual void add_search_path(const char* path) = 0; + virtual void close() { delete this; } }; diff --git a/libraries/timidity/instrum.cpp b/libraries/timidity/instrum.cpp index bd6224cc4..9240de456 100644 --- a/libraries/timidity/instrum.cpp +++ b/libraries/timidity/instrum.cpp @@ -703,7 +703,7 @@ Instruments::~Instruments() drumset[i] = NULL; } } - if (sfreader != nullptr) delete sfreader; + if (sfreader != nullptr) sfreader->close(); sfreader = nullptr; } diff --git a/libraries/timidityplus/instrum.cpp b/libraries/timidityplus/instrum.cpp index b133af280..431147dcf 100644 --- a/libraries/timidityplus/instrum.cpp +++ b/libraries/timidityplus/instrum.cpp @@ -73,7 +73,7 @@ Instruments::~Instruments() free_tone_bank(); free_instrument_map(); - if (sfreader != nullptr) delete sfreader; + if (sfreader != nullptr) sfreader->close(); } void Instruments::free_instrument(Instrument *ip) diff --git a/libraries/wildmidi/wildmidi_lib.cpp b/libraries/wildmidi/wildmidi_lib.cpp index 3401e997a..9286b9825 100644 --- a/libraries/wildmidi/wildmidi_lib.cpp +++ b/libraries/wildmidi/wildmidi_lib.cpp @@ -1326,7 +1326,7 @@ void Instruments::load_patch(struct _mdi *mdi, unsigned short patchid) Instruments::~Instruments() { FreePatches(); - delete sfreader; + sfreader->close(); }