Skip to content

Commit

Permalink
Fixed the "double free" .wav-saving issue (#289)
Browse files Browse the repository at this point in the history
  • Loading branch information
nalquas committed Mar 21, 2020
1 parent 6fec1b6 commit 99635da
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/action.c
Original file line number Diff line number Diff line change
Expand Up @@ -725,8 +725,8 @@ void export_channels_action(void *a, void*b, void*c)

if (f)
{
export_wav(&mused.song, mused.mus.cyd->wavetable_entries, f, i);
fclose(f);
if (export_wav(&mused.song, mused.mus.cyd->wavetable_entries, f, i))
fclose(f); // Call only if not aborted
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/export.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ OTHER DEALINGS IN THE SOFTWARE.

extern GfxDomain *domain;

void export_wav(MusSong *song, CydWavetableEntry * entry, FILE *f, int channel)
bool export_wav(MusSong *song, CydWavetableEntry * entry, FILE *f, int channel)
{
MusEngine mus;
CydEngine cyd;
Expand Down Expand Up @@ -129,6 +129,8 @@ void export_wav(MusSong *song, CydWavetableEntry * entry, FILE *f, int channel)
}
}

return true; // Successful (not aborted)

abort:;

ww_finish(ww);
Expand All @@ -138,5 +140,7 @@ abort:;
cyd_deinit(&cyd);

song->flags &= ~MUS_NO_REPEAT;

return false; // Aborted
}

2 changes: 1 addition & 1 deletion src/export.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ OTHER DEALINGS IN THE SOFTWARE.

#include "snd/music.h"

void export_wav(MusSong *song, CydWavetableEntry * entry, FILE *f, int channel);
bool export_wav(MusSong *song, CydWavetableEntry * entry, FILE *f, int channel);

#endif

0 comments on commit 99635da

Please sign in to comment.