Skip to content

Commit

Permalink
- blocked the destructor in the sound font reader base class.
Browse files Browse the repository at this point in the history
If ZMusic is to act like an external library it may not call delete on external objects because there is no guarantee that they use the same allocator. Deletion must be done as a virtual function to ensure that the correct operator delete gets called, which, unlike the actual destructor is not virtual itself.
  • Loading branch information
coelckers committed Jan 1, 2020
1 parent 7156611 commit fe0a6b0
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
8 changes: 5 additions & 3 deletions libraries/music_common/fileio.h
Expand Up @@ -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.
//
//==========================================================================

Expand Down Expand Up @@ -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; }
};


Expand Down
2 changes: 1 addition & 1 deletion libraries/timidity/instrum.cpp
Expand Up @@ -703,7 +703,7 @@ Instruments::~Instruments()
drumset[i] = NULL;
}
}
if (sfreader != nullptr) delete sfreader;
if (sfreader != nullptr) sfreader->close();
sfreader = nullptr;
}

Expand Down
2 changes: 1 addition & 1 deletion libraries/timidityplus/instrum.cpp
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion libraries/wildmidi/wildmidi_lib.cpp
Expand Up @@ -1326,7 +1326,7 @@ void Instruments::load_patch(struct _mdi *mdi, unsigned short patchid)
Instruments::~Instruments()
{
FreePatches();
delete sfreader;
sfreader->close();
}


Expand Down

0 comments on commit fe0a6b0

Please sign in to comment.