player: avoid leaking memory
This commit is contained in:
@@ -55,6 +55,25 @@ static const int host_bigendian = 0;
|
||||
struct {signed int x:24;} se_struct_24;
|
||||
#define SignExtend24(val) (se_struct_24.x = val)
|
||||
|
||||
void alac_free(alac_file *alac) {
|
||||
if (alac->predicterror_buffer_a)
|
||||
free(alac->predicterror_buffer_a);
|
||||
if (alac->predicterror_buffer_b)
|
||||
free(alac->predicterror_buffer_b);
|
||||
|
||||
if (alac->outputsamples_buffer_a)
|
||||
free(alac->outputsamples_buffer_a);
|
||||
if (alac->outputsamples_buffer_b)
|
||||
free(alac->outputsamples_buffer_b);
|
||||
|
||||
if (alac->uncompressed_bytes_buffer_a)
|
||||
free(alac->uncompressed_bytes_buffer_a);
|
||||
if (alac->uncompressed_bytes_buffer_b)
|
||||
free(alac->uncompressed_bytes_buffer_b);
|
||||
|
||||
free(alac);
|
||||
}
|
||||
|
||||
void alac_allocate_buffers(alac_file *alac)
|
||||
{
|
||||
alac->predicterror_buffer_a = malloc(alac->setinfo_max_samples_per_frame * 4);
|
||||
@@ -1108,6 +1127,8 @@ alac_file *alac_create(int samplesize, int numchannels)
|
||||
{
|
||||
alac_file *newfile = malloc(sizeof(alac_file));
|
||||
|
||||
memset(newfile, 0, sizeof(alac_file));
|
||||
|
||||
newfile->samplesize = samplesize;
|
||||
newfile->numchannels = numchannels;
|
||||
newfile->bytespersample = (samplesize / 8) * numchannels;
|
||||
|
||||
@@ -11,6 +11,7 @@ void alac_decode_frame(alac_file *alac,
|
||||
void *outbuffer, int *outputsize);
|
||||
void alac_set_info(alac_file *alac, char *inputbuffer);
|
||||
void alac_allocate_buffers(alac_file *alac);
|
||||
void alac_free(alac_file *alac);
|
||||
|
||||
struct alac_file
|
||||
{
|
||||
|
||||
@@ -153,16 +153,24 @@ static int init_decoder(int32_t fmtp[12]) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void free_decoder(void) {
|
||||
alac_free(decoder_info);
|
||||
}
|
||||
|
||||
#ifdef FANCY_RESAMPLING
|
||||
static int init_src(void) {
|
||||
int err;
|
||||
if (fancy_resampling)
|
||||
src = src_new(SRC_SINC_MEDIUM_QUALITY, 2, &err);
|
||||
else
|
||||
src = 0;
|
||||
src = NULL;
|
||||
|
||||
return err;
|
||||
}
|
||||
static void free_src(void) {
|
||||
src_delete(src);
|
||||
src = NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void init_buffer(void) {
|
||||
@@ -172,6 +180,12 @@ static void init_buffer(void) {
|
||||
ab_resync();
|
||||
}
|
||||
|
||||
static void free_buffer(void) {
|
||||
int i;
|
||||
for (i=0; i<BUFFER_FRAMES; i++)
|
||||
free(audio_buffer[i].data);
|
||||
}
|
||||
|
||||
void player_put_packet(seq_t seqno, uint8_t *data, int len) {
|
||||
abuf_t *abuf = 0;
|
||||
short buf_fill;
|
||||
@@ -485,9 +499,8 @@ int player_play(stream_cfg *stream) {
|
||||
|
||||
AES_set_decrypt_key(stream->aeskey, 128, &aes);
|
||||
aesiv = stream->aesiv;
|
||||
// XXX these leak memory
|
||||
init_decoder(stream->fmtp);
|
||||
init_buffer();
|
||||
init_decoder(stream->fmtp);
|
||||
#ifdef FANCY_RESAMPLING
|
||||
init_src();
|
||||
#endif
|
||||
@@ -503,4 +516,9 @@ void player_stop(void) {
|
||||
please_stop = 1;
|
||||
pthread_join(player_thread, NULL);
|
||||
config.output->stop();
|
||||
free_buffer();
|
||||
free_decoder();
|
||||
#ifdef FANCY_RESAMPLING
|
||||
free_src();
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user