[SVN] r3555 - trunk/SDL_mixer
svn-owner at libsdl.org
svn-owner at libsdl.org
Tue Feb 26 03:44:21 PST 2008
Author: slouken
Date: 2008-02-26 03:44:20 -0800 (Tue, 26 Feb 2008)
New Revision: 3555
Modified:
trunk/SDL_mixer/music_mad.c
trunk/SDL_mixer/music_mad.h
Log:
Don't free the rwops if it wasn't allocated by the library!
Modified: trunk/SDL_mixer/music_mad.c
===================================================================
--- trunk/SDL_mixer/music_mad.c 2008-02-26 10:50:28 UTC (rev 3554)
+++ trunk/SDL_mixer/music_mad.c 2008-02-26 11:44:20 UTC (rev 3555)
@@ -29,13 +29,20 @@
mad_data *
mad_openFile(const char *filename, SDL_AudioSpec *mixer) {
SDL_RWops *rw;
+ mad_data *mp3_mad;
rw = SDL_RWFromFile(filename, "rb");
if (rw == NULL) {
return NULL;
}
- return mad_openFileRW(rw, mixer);
+ mp3_mad = mad_openFileRW(rw, mixer);
+ if (mp3_mad == NULL) {
+ SDL_FreeRW(rw);
+ return NULL;
+ }
+ mp3_mad->freerw = SDL_TRUE;
+ return data;
}
mad_data *
@@ -43,28 +50,32 @@
mad_data *mp3_mad;
mp3_mad = (mad_data *)malloc(sizeof(mad_data));
- mp3_mad->rw = rw;
- mad_stream_init(&mp3_mad->stream);
- mad_frame_init(&mp3_mad->frame);
- mad_synth_init(&mp3_mad->synth);
- mp3_mad->frames_read = 0;
- mad_timer_reset(&mp3_mad->next_frame_start);
- mp3_mad->volume = MIX_MAX_VOLUME;
- mp3_mad->status = 0;
- mp3_mad->output_begin = 0;
- mp3_mad->output_end = 0;
- mp3_mad->mixer = *mixer;
-
+ if (mp3_mad) {
+ mp3_mad->rw = rw;
+ mp3_mad->freerw = SDL_FALSE;
+ mad_stream_init(&mp3_mad->stream);
+ mad_frame_init(&mp3_mad->frame);
+ mad_synth_init(&mp3_mad->synth);
+ mp3_mad->frames_read = 0;
+ mad_timer_reset(&mp3_mad->next_frame_start);
+ mp3_mad->volume = MIX_MAX_VOLUME;
+ mp3_mad->status = 0;
+ mp3_mad->output_begin = 0;
+ mp3_mad->output_end = 0;
+ mp3_mad->mixer = *mixer;
+ }
return mp3_mad;
}
void
mad_closeFile(mad_data *mp3_mad) {
- SDL_FreeRW(mp3_mad->rw);
mad_stream_finish(&mp3_mad->stream);
mad_frame_finish(&mp3_mad->frame);
mad_synth_finish(&mp3_mad->synth);
+ if (mp3_mad->freerw) {
+ SDL_FreeRW(mp3_mad->rw);
+ }
free(mp3_mad);
}
Modified: trunk/SDL_mixer/music_mad.h
===================================================================
--- trunk/SDL_mixer/music_mad.h 2008-02-26 10:50:28 UTC (rev 3554)
+++ trunk/SDL_mixer/music_mad.h 2008-02-26 11:44:20 UTC (rev 3555)
@@ -43,6 +43,7 @@
typedef struct {
SDL_RWops *rw;
+ SDL_bool freerw;
struct mad_stream stream;
struct mad_frame frame;
struct mad_synth synth;
More information about the SVN
mailing list