music_flac.c
changeset 521 565549e046b0
parent 518 8bc9b5fd2aae
child 522 a70c0ee38c9f
     1.1 --- a/music_flac.c	Sat Dec 31 14:23:44 2011 -0500
     1.2 +++ b/music_flac.c	Sat Dec 31 18:32:49 2011 -0500
     1.3 @@ -60,7 +60,7 @@
     1.4  		SDL_SetError ("Couldn't open %s", file);
     1.5  		return NULL;
     1.6  	}
     1.7 -	return FLAC_new_RW (rw);
     1.8 +	return FLAC_new_RW (rw, 1);
     1.9  }
    1.10  
    1.11  static FLAC__StreamDecoderReadStatus flac_read_music_cb(
    1.12 @@ -313,7 +313,7 @@
    1.13  }
    1.14  
    1.15  /* Load an FLAC stream from an SDL_RWops object */
    1.16 -FLAC_music *FLAC_new_RW(SDL_RWops *rw)
    1.17 +FLAC_music *FLAC_new_RW(SDL_RWops *rw, int freerw)
    1.18  {
    1.19  	FLAC_music *music;
    1.20  	int init_stage = 0;
    1.21 @@ -327,6 +327,7 @@
    1.22  		FLAC_setvolume (music, MIX_MAX_VOLUME);
    1.23  		music->section = -1;
    1.24  		music->rwops = rw;
    1.25 +		music->freerw = freerw;
    1.26  		music->flac_data.max_to_read = 0;
    1.27  		music->flac_data.overflow = NULL;
    1.28  		music->flac_data.overflow_len = 0;
    1.29 @@ -375,14 +376,19 @@
    1.30  				case 1:
    1.31  				case 0:
    1.32  					free(music);
    1.33 -					SDL_RWclose(rw);
    1.34 +					if (freerw) {
    1.35 +						SDL_RWclose(rw);
    1.36 +					}
    1.37  					break;
    1.38  			}
    1.39  			return NULL;
    1.40  		}
    1.41 -	}
    1.42 -	else {
    1.43 +	} else {
    1.44  		SDL_OutOfMemory();
    1.45 +		if (freerw) {
    1.46 +			SDL_RWclose(rw);
    1.47 +		}
    1.48 +		return NULL;
    1.49  	}
    1.50  
    1.51  	return music;
    1.52 @@ -556,6 +562,9 @@
    1.53  			free (music->cvt.buf);
    1.54  		}
    1.55  
    1.56 +		if (music->freerw) {
    1.57 +			SDL_RWclose(music->rwops);
    1.58 +		}
    1.59  		free (music);
    1.60  	}
    1.61  }