diff options
author | waker <wakeroid@gmail.com> | 2012-08-04 13:45:00 +0200 |
---|---|---|
committer | waker <wakeroid@gmail.com> | 2012-08-04 13:45:00 +0200 |
commit | 7bcfb80083304ae771b49db1c97f1e54e04a51b2 (patch) | |
tree | de10a805cd81c76ed9de26114c9598ff1096a6da /plugins/alac | |
parent | 8a1585fd4d2d7ac6a5297a6166d3090e0c49ae90 (diff) |
alac: fixed few memleaks
Diffstat (limited to 'plugins/alac')
-rw-r--r-- | plugins/alac/alac_plugin.c | 18 | ||||
-rw-r--r-- | plugins/alac/demux.c | 26 | ||||
-rw-r--r-- | plugins/alac/demux.h | 2 | ||||
-rw-r--r-- | plugins/alac/stream.c | 2 |
4 files changed, 40 insertions, 8 deletions
diff --git a/plugins/alac/alac_plugin.c b/plugins/alac/alac_plugin.c index ba1e895b..dc303bc1 100644 --- a/plugins/alac/alac_plugin.c +++ b/plugins/alac/alac_plugin.c @@ -203,6 +203,7 @@ alacplug_free (DB_fileinfo_t *_info) { if (info->stream) { stream_destroy (info->stream); } + qtmovie_free_demux (&info->demux_res); if (info->alac) { alac_file_free (info->alac); } @@ -456,6 +457,7 @@ alacplug_insert (ddb_playlist_t *plt, DB_playItem_t *after, const char *fname) { mp4ff_t *mp4 = NULL; DB_playItem_t *it = NULL; demux_res_t demux_res; + memset (&demux_res, 0, sizeof (demux_res)); stream_t *stream; DB_FILE *fp = deadbeef->fopen (fname); if (!fp) { @@ -529,16 +531,21 @@ alacplug_insert (ddb_playlist_t *plt, DB_playItem_t *after, const char *fname) { mp4ff_close (mp4); mp4 = NULL; } + int samplerate = demux_res.sample_rate; + int bps = demux_res.sample_size; + int channels = demux_res.num_channels; + + qtmovie_free_demux (&demux_res); if (duration > 0) { char s[100]; snprintf (s, sizeof (s), "%lld", fsize); deadbeef->pl_add_meta (it, ":FILE_SIZE", s); - snprintf (s, sizeof (s), "%d", demux_res.sample_size); + snprintf (s, sizeof (s), "%d", bps); deadbeef->pl_add_meta (it, ":BPS", s); - snprintf (s, sizeof (s), "%d", demux_res.num_channels); + snprintf (s, sizeof (s), "%d", channels); deadbeef->pl_add_meta (it, ":CHANNELS", s); - snprintf (s, sizeof (s), "%d", demux_res.sample_rate); + snprintf (s, sizeof (s), "%d", samplerate); deadbeef->pl_add_meta (it, ":SAMPLERATE", s); int br = (int)roundf(fsize / duration * 8 / 1000); snprintf (s, sizeof (s), "%d", br); @@ -549,7 +556,7 @@ alacplug_insert (ddb_playlist_t *plt, DB_playItem_t *after, const char *fname) { DB_playItem_t *cue = NULL; if (cuesheet) { - cue = deadbeef->plt_insert_cue_from_buffer (plt, after, it, cuesheet, strlen (cuesheet), totalsamples, demux_res.sample_rate); + cue = deadbeef->plt_insert_cue_from_buffer (plt, after, it, cuesheet, strlen (cuesheet), totalsamples, samplerate); if (cue) { deadbeef->pl_item_unref (it); deadbeef->pl_item_unref (cue); @@ -559,7 +566,7 @@ alacplug_insert (ddb_playlist_t *plt, DB_playItem_t *after, const char *fname) { } deadbeef->pl_unlock (); - cue = deadbeef->plt_insert_cue (plt, after, it, totalsamples, demux_res.sample_rate); + cue = deadbeef->plt_insert_cue (plt, after, it, totalsamples, samplerate); if (cue) { deadbeef->pl_item_unref (it); deadbeef->pl_item_unref (cue); @@ -577,6 +584,7 @@ error: if (mp4) { mp4ff_close (mp4); } + qtmovie_free_demux (&demux_res); return it; } diff --git a/plugins/alac/demux.c b/plugins/alac/demux.c index b495d1a5..77714530 100644 --- a/plugins/alac/demux.c +++ b/plugins/alac/demux.c @@ -584,6 +584,7 @@ int qtmovie_read(stream_t *file, demux_res_t *demux_res) qtmovie_t *qtmovie; qtmovie = (qtmovie_t*)malloc(sizeof(qtmovie_t)); + memset (qtmovie, 0, sizeof (qtmovie_t)); /* construct the stream */ qtmovie->stream = file; @@ -601,12 +602,14 @@ int qtmovie_read(stream_t *file, demux_res_t *demux_res) chunk_len = stream_read_uint32(qtmovie->stream); if (stream_eof(qtmovie->stream)) { + free (qtmovie); return 0; } if (chunk_len == 1) { trace ("need 64bit support\n"); + free (qtmovie); return 0; } chunk_id = stream_read_uint32(qtmovie->stream); @@ -617,11 +620,15 @@ int qtmovie_read(stream_t *file, demux_res_t *demux_res) read_chunk_ftyp(qtmovie, chunk_len); break; case MAKEFOURCC('m','o','o','v'): - if (read_chunk_moov(qtmovie, chunk_len) == 0) + if (read_chunk_moov(qtmovie, chunk_len) == 0) { + free (qtmovie); return 0; /* failed to read moov, can't do anything */ + } if (found_mdat) { - return set_saved_mdat(qtmovie); + int res = set_saved_mdat(qtmovie); + free (qtmovie); + return res; } found_moov = 1; break; @@ -631,8 +638,10 @@ int qtmovie_read(stream_t *file, demux_res_t *demux_res) */ case MAKEFOURCC('m','d','a','t'): read_chunk_mdat(qtmovie, chunk_len, !found_moov); - if (found_moov) + if (found_moov) { + free (qtmovie); return 1; + } found_mdat = 1; break; @@ -643,11 +652,22 @@ int qtmovie_read(stream_t *file, demux_res_t *demux_res) default: trace ("(top) unknown chunk id: %c%c%c%c\n", SPLITFOURCC(chunk_id)); + free (qtmovie); return 0; } } + free (qtmovie); return 0; } +void qtmovie_free_demux (demux_res_t *demux_res) { + if (demux_res->time_to_sample) { + free (demux_res->time_to_sample); + } + if (demux_res->sample_byte_size) { + free (demux_res->sample_byte_size); + } + memset (demux_res, 0, sizeof (demux_res_t)); +} diff --git a/plugins/alac/demux.h b/plugins/alac/demux.h index de4a3114..091b1544 100644 --- a/plugins/alac/demux.h +++ b/plugins/alac/demux.h @@ -58,5 +58,7 @@ int qtmovie_read(stream_t *stream, demux_res_t *demux_res); (char)code #endif +void qtmovie_free_demux (demux_res_t *demux_res); + #endif /* DEMUX_H */ diff --git a/plugins/alac/stream.c b/plugins/alac/stream.c index 0c99a32b..cb969dd0 100644 --- a/plugins/alac/stream.c +++ b/plugins/alac/stream.c @@ -32,6 +32,7 @@ #include <stdlib.h> #include <errno.h> +#include <string.h> #ifdef _WIN32 #include "stdint_win.h" #else @@ -169,6 +170,7 @@ stream_t *stream_create_file(DB_FILE *file, int bigendian, int64_t junk_offset) stream_t *new_stream; new_stream = (stream_t*)malloc(sizeof(stream_t)); + memset (new_stream, 0, sizeof (new_stream)); new_stream->f = file; new_stream->bigendian = bigendian; new_stream->eof = 0; |