From 9cda41d51a50a319676d24ba85dc5f39747ba356 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Thu, 13 Dec 2007 17:31:53 +0100 Subject: Free the temporary variables that are allocated, avoid memory leaks. (transplanted from c994a2508893efc4c85f5b49600b7dceec5c890e) --HG-- extra : transplant_source : %C9%94%A2P%88%93%EF%C4%C8_%5BI%60%0B%7D%CE%EC%5C%89%0E --- src/demuxers/demux_matroska.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/demuxers') diff --git a/src/demuxers/demux_matroska.c b/src/demuxers/demux_matroska.c index 0169651a0..4f3476049 100644 --- a/src/demuxers/demux_matroska.c +++ b/src/demuxers/demux_matroska.c @@ -1181,8 +1181,10 @@ static int parse_track_entry(demux_matroska_t *this, matroska_track_t *track) { case MATROSKA_ID_TR_CODECID: { char *codec_id = malloc (elem.len + 1); lprintf("CodecID\n"); - if (!ebml_read_ascii(ebml, &elem, codec_id)) + if (!ebml_read_ascii(ebml, &elem, codec_id)) { + free(codec_id); return 0; + } codec_id[elem.len] = '\0'; track->codec_id = codec_id; } @@ -1191,8 +1193,10 @@ static int parse_track_entry(demux_matroska_t *this, matroska_track_t *track) { case MATROSKA_ID_TR_CODECPRIVATE: { char *codec_private = malloc (elem.len); lprintf("CodecPrivate\n"); - if (!ebml_read_binary(ebml, &elem, codec_private)) + if (!ebml_read_binary(ebml, &elem, codec_private)) { + free(codec_private); return 0; + } track->codec_private = codec_private; track->codec_private_len = elem.len; } @@ -1201,8 +1205,10 @@ static int parse_track_entry(demux_matroska_t *this, matroska_track_t *track) { case MATROSKA_ID_TR_LANGUAGE: { char *language = malloc (elem.len + 1); lprintf("Language\n"); - if (!ebml_read_ascii(ebml, &elem, language)) + if (!ebml_read_ascii(ebml, &elem, language)) { + free(language); return 0; + } language[elem.len] = '\0'; track->language = language; } -- cgit v1.2.3 From d1d18588d3bc91f72f6e9534d1f90b8aac7c118f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Thu, 13 Dec 2007 19:38:53 +0100 Subject: Set stream information only when reading a streaminfo FLAC block. (transplanted from 6d9f36be48839984c3888f3d803319942c4d76e6) --HG-- extra : transplant_source : E%81r%E5-%5B%C2%21%15h%E3_%CB%23%25%9B%01l%03Y --- src/demuxers/demux_ogg.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/demuxers') diff --git a/src/demuxers/demux_ogg.c b/src/demuxers/demux_ogg.c index 4eacf7070..9ed39f12d 100644 --- a/src/demuxers/demux_ogg.c +++ b/src/demuxers/demux_ogg.c @@ -1221,16 +1221,17 @@ static void decode_flac_header (demux_ogg_t *this, const int stream_num, ogg_pac case FLAC_BLOCKTYPE_STREAMINFO: _x_assert(header.length == FLAC_STREAMINFO_SIZE); _x_parse_flac_streaminfo_block(&op->packet[17], &streaminfo); + + _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_SAMPLERATE, streaminfo.samplerate); + _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_CHANNELS, streaminfo.channels); + _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_BITS, streaminfo.bits_per_sample); + break; } this->si[stream_num]->buf_types = BUF_AUDIO_FLAC +this->num_audio_streams++; - _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_SAMPLERATE, streaminfo.samplerate); - _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_CHANNELS, streaminfo.channels); - _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_BITS, streaminfo.bits_per_sample); - this->si[stream_num]->factor = 90000; buf = this->audio_fifo->buffer_pool_alloc(this->audio_fifo); -- cgit v1.2.3 From b6df7d39efa2fffefe0685d271e28038c484512a Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Sun, 16 Dec 2007 14:20:34 +0000 Subject: Drop the priority of the aud demuxer. It has been observed claiming files which should be claimed by other demuxers such as playlist or real. --- src/demuxers/group_audio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/demuxers') diff --git a/src/demuxers/group_audio.c b/src/demuxers/group_audio.c index 78bf4012b..d3832c36d 100644 --- a/src/demuxers/group_audio.c +++ b/src/demuxers/group_audio.c @@ -42,7 +42,7 @@ static const demuxer_info_t demux_info_ac3 = { }; static const demuxer_info_t demux_info_aud = { - 10 /* priority */ + -2 /* priority */ }; static const demuxer_info_t demux_info_aiff = { -- cgit v1.2.3 From fdf9cb58ce03df58c25dc9dd0c9f939abd343183 Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Sun, 16 Dec 2007 14:23:25 +0000 Subject: Tell the Real demuxer about http references. --- src/demuxers/demux_real.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/demuxers') diff --git a/src/demuxers/demux_real.c b/src/demuxers/demux_real.c index 11c5069eb..938e1ca24 100644 --- a/src/demuxers/demux_real.c +++ b/src/demuxers/demux_real.c @@ -820,8 +820,8 @@ static int demux_real_parse_references( demux_real_t *this) { if( !strncmp(&buf[i],"-->",3) ) comment = 0; - if( (!strncmp(&buf[i],"pnm://",6) || !strncmp(&buf[i],"rtsp://",7)) && - !comment ) { + if( (!strncmp(&buf[i],"pnm://",6) || !strncmp(&buf[i],"rtsp://",7) || + !strncmp(&buf[i],"http://",7)) && !comment ) { for(j=i; buf[j] && buf[j] != '"' && !isspace(buf[j]); j++ ) ; buf[j]='\0'; @@ -1532,7 +1532,8 @@ static int real_check_stream_type(uint8_t *buf, int len) return 1; buf[len] = '\0'; - if( strstr(buf,"pnm://") || strstr(buf,"rtsp://") || strstr(buf,"") ) + if( strstr(buf,"pnm://") || strstr(buf,"rtsp://") || strstr(buf,"") || + strstr(buf,"http://") ) return 2; return 0; -- cgit v1.2.3 From 8a3706ba2814436bba1e164bf29cd02c6125083b Mon Sep 17 00:00:00 2001 From: Matthias Kretz Date: Mon, 17 Dec 2007 22:00:34 +0100 Subject: add video/flv and application/x-flash-video MIME aliases as used by shared-mime --- src/demuxers/demux_flv.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/demuxers') diff --git a/src/demuxers/demux_flv.c b/src/demuxers/demux_flv.c index 39c34d91e..5669a4b2e 100644 --- a/src/demuxers/demux_flv.c +++ b/src/demuxers/demux_flv.c @@ -892,7 +892,9 @@ static const char *get_extensions (demux_class_t *this_gen) { } static const char *get_mimetypes (demux_class_t *this_gen) { - return "video/x-flv: flv: Flash video;"; + return "video/x-flv: flv: Flash video;" + "video/flv: flv: Flash video;" + "application/x-flash-video: flv: Flash video;" } static void class_dispose (demux_class_t *this_gen) { -- cgit v1.2.3 From eacdc6fc2e37f80cc03b022988112741979724e6 Mon Sep 17 00:00:00 2001 From: Matthias Kretz Date: Mon, 17 Dec 2007 22:16:52 +0100 Subject: compile --- src/demuxers/demux_flv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/demuxers') diff --git a/src/demuxers/demux_flv.c b/src/demuxers/demux_flv.c index 5669a4b2e..bdb33d21d 100644 --- a/src/demuxers/demux_flv.c +++ b/src/demuxers/demux_flv.c @@ -894,7 +894,7 @@ static const char *get_extensions (demux_class_t *this_gen) { static const char *get_mimetypes (demux_class_t *this_gen) { return "video/x-flv: flv: Flash video;" "video/flv: flv: Flash video;" - "application/x-flash-video: flv: Flash video;" + "application/x-flash-video: flv: Flash video;"; } static void class_dispose (demux_class_t *this_gen) { -- cgit v1.2.3 From b864b902b6ba16c7bcee14fcb7f71cac640a23c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 16:49:04 +0100 Subject: Fix demuxing of VCDs, DVDs and PVR streams. --- src/demuxers/demux_mpeg_block.c | 36 ++---------------------------------- 1 file changed, 2 insertions(+), 34 deletions(-) (limited to 'src/demuxers') diff --git a/src/demuxers/demux_mpeg_block.c b/src/demuxers/demux_mpeg_block.c index 2f7c48d44..91b69328c 100644 --- a/src/demuxers/demux_mpeg_block.c +++ b/src/demuxers/demux_mpeg_block.c @@ -1452,39 +1452,7 @@ static demux_plugin_t *open_plugin (demux_class_t *class_gen, xine_stream_t *str } break; - case METHOD_BY_MRL: { - char *ending; - - const char *const mrl = input->get_mrl (input); - - if(!strncmp(mrl, "vcd:", 4)) { - this->blocksize = 2324; - demux_mpeg_block_accept_input (this, input); - } else if(!strncmp(mrl, "dvd:", 4) || !strncmp(mrl, "pvr:", 4)) { - this->blocksize = 2048; - demux_mpeg_block_accept_input (this, input); - } else { - ending = strrchr(mrl, '.'); - - if (!ending) { - free (this->scratch_base); - free (this); - return NULL; - } - if ( (!strncasecmp (ending, ".vob", 4)) || - (!strncmp((ending + 3), "mpeg2", 5)) || - (!strncmp((ending + 3), "mpeg1", 5)) ) { - this->blocksize = 2048; - demux_mpeg_block_accept_input(this, input); - } else { - free (this->scratch_base); - free (this); - return NULL; - } - } - } - break; - + case METHOD_BY_MRL: case METHOD_EXPLICIT: { this->blocksize = input->get_blocksize(input); @@ -1525,7 +1493,7 @@ static void *init_plugin (xine_t *xine, void *data) { this->demux_class.description = N_("DVD/VOB demux plugin"); this->demux_class.identifier = "MPEG_BLOCK"; this->demux_class.mimetypes = NULL; - this->demux_class.extensions = "vob"; + this->demux_class.extensions = "vob vcd:/ dvd:/ pvr:/"; this->demux_class.dispose = default_demux_class_dispose; return this; -- cgit v1.2.3 From ac983bbadbd6b518539390fa3608eaf102e6a2b1 Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Tue, 18 Dec 2007 17:01:33 +0000 Subject: Allow vdr/netvdr MRLs to work without requiring #demux:mpeg_pes. (This doesn't work with detection by content.) --- src/demuxers/demux_mpeg_pes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/demuxers') diff --git a/src/demuxers/demux_mpeg_pes.c b/src/demuxers/demux_mpeg_pes.c index 1ec5b8365..d47c1ed01 100644 --- a/src/demuxers/demux_mpeg_pes.c +++ b/src/demuxers/demux_mpeg_pes.c @@ -1754,7 +1754,7 @@ static void *init_plugin (xine_t *xine, void *data) { this->demux_class.description = N_("mpeg pes demux plugin"); this->demux_class.identifier = "MPEG_PES"; this->demux_class.mimetypes = NULL; - this->demux_class.extensions = "pes"; + this->demux_class.extensions = "pes vdr:/ netvdr:/"; this->demux_class.dispose = default_demux_class_dispose; return this; -- cgit v1.2.3 From 456f5a5a8bc07ba783cddbaca3716add185a5e7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 20:04:19 +0100 Subject: Use xine_xmalloc rather than setting everything at zero by hand. --- src/demuxers/ebml.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) (limited to 'src/demuxers') diff --git a/src/demuxers/ebml.c b/src/demuxers/ebml.c index 218046cf5..532f41ebf 100644 --- a/src/demuxers/ebml.c +++ b/src/demuxers/ebml.c @@ -41,20 +41,10 @@ ebml_parser_t *new_ebml_parser (xine_t *xine, input_plugin_t *input) { ebml_parser_t *ebml; - ebml = malloc(sizeof(ebml_parser_t)); + ebml = xine_xmalloc(sizeof(ebml_parser_t)); ebml->xine = xine; ebml->input = input; - ebml->version = 0; - ebml->read_version = 0; - ebml->max_id_len = 0; - ebml->max_size_len = 0; - ebml->doctype = NULL; - ebml->doctype_version = 0; - ebml->doctype_read_version = 0; - - ebml->level = 0; - return ebml; } -- cgit v1.2.3 From 6bcba9598c0e23ab4475efc4e5f227f94614d445 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 20:06:46 +0100 Subject: Simplify code by returning immediately in case of error. --- src/demuxers/ebml.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'src/demuxers') diff --git a/src/demuxers/ebml.c b/src/demuxers/ebml.c index 532f41ebf..23a27f674 100644 --- a/src/demuxers/ebml.c +++ b/src/demuxers/ebml.c @@ -315,25 +315,25 @@ int ebml_read_date (ebml_parser_t *ebml, ebml_elem_t *elem, int64_t *date) { int ebml_read_master (ebml_parser_t *ebml, ebml_elem_t *elem) { ebml_elem_t *top_elem; - if (ebml->level >= 0) { - top_elem = &ebml->elem_stack[ebml->level]; - top_elem->start = elem->start; - top_elem->len = elem->len; - top_elem->id = elem->id; - - ebml->level++; - lprintf("id: 0x%x, len: %" PRIu64 ", level: %d\n", elem->id, elem->len, ebml->level); - if (ebml->level >= EBML_STACK_SIZE) { - xprintf(ebml->xine, XINE_VERBOSITY_LOG, - "ebml: max level exceeded\n"); - return 0; - } - return 1; - } else { + if (ebml->level < 0) { xprintf(ebml->xine, XINE_VERBOSITY_LOG, "ebml: invalid current level\n"); return 0; } + + top_elem = &ebml->elem_stack[ebml->level]; + top_elem->start = elem->start; + top_elem->len = elem->len; + top_elem->id = elem->id; + + ebml->level++; + lprintf("id: 0x%x, len: %" PRIu64 ", level: %d\n", elem->id, elem->len, ebml->level); + if (ebml->level >= EBML_STACK_SIZE) { + xprintf(ebml->xine, XINE_VERBOSITY_LOG, + "ebml: max level exceeded\n"); + return 0; + } + return 1; } int ebml_read_binary(ebml_parser_t *ebml, ebml_elem_t *elem, void *binary) { -- cgit v1.2.3 From d3c734f256cf1f78042e322f2bdfab7dfe8f5967 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 20:07:22 +0100 Subject: Simplify code. --- src/demuxers/ebml.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src/demuxers') diff --git a/src/demuxers/ebml.c b/src/demuxers/ebml.c index 23a27f674..d5f7bb9b5 100644 --- a/src/demuxers/ebml.c +++ b/src/demuxers/ebml.c @@ -337,10 +337,7 @@ int ebml_read_master (ebml_parser_t *ebml, ebml_elem_t *elem) { } int ebml_read_binary(ebml_parser_t *ebml, ebml_elem_t *elem, void *binary) { - if (!ebml_read_elem_data(ebml, binary, elem->len)) - return 0; - - return 1; + return !!ebml_read_elem_data(ebml, binary, elem->len); } int ebml_check_header(ebml_parser_t *ebml) { -- cgit v1.2.3 From 485a597194d373aa233017be47c8cfa1b92748d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 20:15:26 +0100 Subject: Don't test for the pointer before freeing. --- src/demuxers/demux_qt.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/demuxers') diff --git a/src/demuxers/demux_qt.c b/src/demuxers/demux_qt.c index b46cbc593..f9b14f9e8 100644 --- a/src/demuxers/demux_qt.c +++ b/src/demuxers/demux_qt.c @@ -651,8 +651,7 @@ static void free_qt_info(qt_info *info) { for (j = 0; j < info->traks[i].stsd_atoms_count; j++) { if (info->traks[i].type == MEDIA_AUDIO) { free(info->traks[i].stsd_atoms[j].audio.properties_atom); - if (info->traks[i].stsd_atoms[j].audio.wave) - free(info->traks[i].stsd_atoms[j].audio.wave); + free(info->traks[i].stsd_atoms[j].audio.wave); } else if (info->traks[i].type == MEDIA_VIDEO) free(info->traks[i].stsd_atoms[j].video.properties_atom); } -- cgit v1.2.3 From 38b08ea4a1a3130eb05139b7121ece98a4c3d232 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 20:20:04 +0100 Subject: Alloc preview only when needed; use zeroed allocation rather than memset. --- src/demuxers/demux_qt.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/demuxers') diff --git a/src/demuxers/demux_qt.c b/src/demuxers/demux_qt.c index f9b14f9e8..e2db5855a 100644 --- a/src/demuxers/demux_qt.c +++ b/src/demuxers/demux_qt.c @@ -686,13 +686,12 @@ static int is_qt_file(input_plugin_t *qt_file) { int64_t moov_atom_size = -1; int i; unsigned char atom_preamble[ATOM_PREAMBLE_SIZE]; - unsigned char preview[MAX_PREVIEW_SIZE]; int len; /* if the input is non-seekable, be much more stringent about qualifying * a QT file: In this case, the moov must be the first atom in the file */ if ((qt_file->get_capabilities(qt_file) & INPUT_CAP_SEEKABLE) == 0) { - memset (&preview, 0, MAX_PREVIEW_SIZE); + unsigned char preview[MAX_PREVIEW_SIZE] = { 0, }; len = qt_file->get_optional_data(qt_file, preview, INPUT_OPTIONAL_DATA_PREVIEW); if (_X_BE_32(&preview[4]) == MOOV_ATOM) return 1; -- cgit v1.2.3 From ccb545fca89e270271b9ace18289db433e2e1d09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 20:20:52 +0100 Subject: Don't use an if when returning a comparison. --- src/demuxers/demux_qt.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src/demuxers') diff --git a/src/demuxers/demux_qt.c b/src/demuxers/demux_qt.c index e2db5855a..402b7be99 100644 --- a/src/demuxers/demux_qt.c +++ b/src/demuxers/demux_qt.c @@ -706,10 +706,7 @@ static int is_qt_file(input_plugin_t *qt_file) { i = moov_atom_size + ATOM_PREAMBLE_SIZE; if (i >= MAX_PREVIEW_SIZE) return 0; - if (_X_BE_32(&preview[i - 4]) == MOOV_ATOM) - return 1; - else - return 0; + return _X_BE_32(&preview[i - 4]) == MOOV_ATOM; } else return 0; } -- cgit v1.2.3 From 8d1a32f1880988b27a1da296d0670f24e89954cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 20:21:41 +0100 Subject: Return right away if the atom is not an FTYP. --- src/demuxers/demux_qt.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'src/demuxers') diff --git a/src/demuxers/demux_qt.c b/src/demuxers/demux_qt.c index 402b7be99..3e5faf390 100644 --- a/src/demuxers/demux_qt.c +++ b/src/demuxers/demux_qt.c @@ -696,19 +696,19 @@ static int is_qt_file(input_plugin_t *qt_file) { if (_X_BE_32(&preview[4]) == MOOV_ATOM) return 1; else { - if (_X_BE_32(&preview[4]) == FTYP_ATOM) { - /* show some lenience if the first atom is 'ftyp'; the second atom - * could be 'moov' */ - moov_atom_size = _X_BE_32(&preview[0]); - /* compute the size of the current atom plus the preamble of the - * next atom; if the size is within the range on the preview buffer - * then the next atom's preamble is in the preview buffer */ - i = moov_atom_size + ATOM_PREAMBLE_SIZE; - if (i >= MAX_PREVIEW_SIZE) - return 0; - return _X_BE_32(&preview[i - 4]) == MOOV_ATOM; - } else - return 0; + if (_X_BE_32(&preview[4]) != FTYP_ATOM) + return 0; + + /* show some lenience if the first atom is 'ftyp'; the second atom + * could be 'moov' */ + moov_atom_size = _X_BE_32(&preview[0]); + /* compute the size of the current atom plus the preamble of the + * next atom; if the size is within the range on the preview buffer + * then the next atom's preamble is in the preview buffer */ + i = moov_atom_size + ATOM_PREAMBLE_SIZE; + if (i >= MAX_PREVIEW_SIZE) + return 0; + return _X_BE_32(&preview[i - 4]) == MOOV_ATOM; } } -- cgit v1.2.3 From 0deccd94faa1565e28bebefafed7fe32b369d2b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 20:25:38 +0100 Subject: Simplify code, set ftyp_atom_size at once. --- src/demuxers/demux_qt.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src/demuxers') diff --git a/src/demuxers/demux_qt.c b/src/demuxers/demux_qt.c index 3e5faf390..2fb79fe2a 100644 --- a/src/demuxers/demux_qt.c +++ b/src/demuxers/demux_qt.c @@ -700,15 +700,14 @@ static int is_qt_file(input_plugin_t *qt_file) { return 0; /* show some lenience if the first atom is 'ftyp'; the second atom - * could be 'moov' */ - moov_atom_size = _X_BE_32(&preview[0]); - /* compute the size of the current atom plus the preamble of the + * could be 'moov' + * compute the size of the current atom plus the preamble of the * next atom; if the size is within the range on the preview buffer * then the next atom's preamble is in the preview buffer */ - i = moov_atom_size + ATOM_PREAMBLE_SIZE; - if (i >= MAX_PREVIEW_SIZE) + uint64_t ftyp_atom_size = _X_BE_32(&preview[0]) + ATOM_PREAMBLE_SIZE; + if (ftyp_atom_size >= MAX_PREVIEW_SIZE) return 0; - return _X_BE_32(&preview[i - 4]) == MOOV_ATOM; + return _X_BE_32(&preview[ftyp_atom_size - 4]) == MOOV_ATOM; } } -- cgit v1.2.3 From 1a366138f0b39cfa1d8586d54f5dfce296a001d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 20:28:55 +0100 Subject: Allocate atom_preamble only when it's actually going to be used. --- src/demuxers/demux_qt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/demuxers') diff --git a/src/demuxers/demux_qt.c b/src/demuxers/demux_qt.c index 2fb79fe2a..3cd573530 100644 --- a/src/demuxers/demux_qt.c +++ b/src/demuxers/demux_qt.c @@ -685,7 +685,6 @@ static int is_qt_file(input_plugin_t *qt_file) { off_t moov_atom_offset = -1; int64_t moov_atom_size = -1; int i; - unsigned char atom_preamble[ATOM_PREAMBLE_SIZE]; int len; /* if the input is non-seekable, be much more stringent about qualifying @@ -715,6 +714,7 @@ static int is_qt_file(input_plugin_t *qt_file) { if (moov_atom_offset == -1) { return 0; } else { + unsigned char atom_preamble[ATOM_PREAMBLE_SIZE]; /* check that the next atom in the chunk contains alphanumeric * characters in the atom type field; if not, disqualify the file * as a QT file */ -- cgit v1.2.3 From d3298c9017077d3ea3ea91110dcac349d58448a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 20:34:40 +0100 Subject: Replace seven calls to parse_data_atom with a single call, and then set the value on the proper structure. This way, parse_data_atom is inlined by GCC. --- src/demuxers/demux_qt.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'src/demuxers') diff --git a/src/demuxers/demux_qt.c b/src/demuxers/demux_qt.c index 3cd573530..4c9399608 100644 --- a/src/demuxers/demux_qt.c +++ b/src/demuxers/demux_qt.c @@ -801,31 +801,33 @@ static void parse_meta_atom(qt_info *info, unsigned char *meta_atom) { const uint8_t *const sub_atom = &meta_atom[j]; const qt_atom sub_atom_code = _X_BE_32(&sub_atom[4]); const uint32_t sub_atom_size = _X_BE_32(&sub_atom[0]); + char *const data_atom = parse_data_atom(&sub_atom[8]); switch(sub_atom_code) { case ART_ATOM: - info->artist = parse_data_atom(&sub_atom[8]); + info->artist = data_atom; break; case NAM_ATOM: - info->name = parse_data_atom(&sub_atom[8]); + info->name = data_atom; break; case ALB_ATOM: - info->album = parse_data_atom(&sub_atom[8]); + info->album = data_atom; break; case GEN_ATOM: - info->genre = parse_data_atom(&sub_atom[8]); + info->genre = data_atom; break; case CMT_ATOM: - info->comment = parse_data_atom(&sub_atom[8]); + info->comment = data_atom; break; case WRT_ATOM: - info->composer = parse_data_atom(&sub_atom[8]); + info->composer = data_atom; break; case DAY_ATOM: - info->year = parse_data_atom(&sub_atom[8]); + info->year = data_atom; break; default: debug_meta_load("unknown atom %08x in ilst\n", sub_atom_code); + free(data_atom); } j += sub_atom_size; -- cgit v1.2.3 From c57b06b240fd159758f93206726556f31e12a8d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 20:36:37 +0100 Subject: Declare color_* variables only when actually used. --- src/demuxers/demux_qt.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'src/demuxers') diff --git a/src/demuxers/demux_qt.c b/src/demuxers/demux_qt.c index 4c9399608..ae657fb66 100644 --- a/src/demuxers/demux_qt.c +++ b/src/demuxers/demux_qt.c @@ -1004,18 +1004,17 @@ static qt_error parse_trak_atom (qt_trak *trak, const uint32_t current_stsd_atom_size = _X_BE_32(&trak_atom[atom_pos - 4]); - /* for palette traversal */ - int color_depth; - int color_flag; - int color_start; - int color_count; - int color_end; - int color_index; - int color_dec; - int color_greyscale; - const unsigned char *color_table; - if (trak->type == MEDIA_VIDEO) { + /* for palette traversal */ + int color_depth; + int color_flag; + int color_start; + int color_count; + int color_end; + int color_index; + int color_dec; + int color_greyscale; + const unsigned char *color_table; trak->stsd_atoms[k].video.media_id = k + 1; trak->stsd_atoms[k].video.properties_offset = properties_offset; -- cgit v1.2.3 From 80826e77cf419d92711e175dcc9e40edaecfd7f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 20:43:36 +0100 Subject: Use calloc() when the allocated size would be counted by multiplying the size of an item for the number of items. Also don't memset calloc()ed areas to zero. --- src/demuxers/demux_qt.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) (limited to 'src/demuxers') diff --git a/src/demuxers/demux_qt.c b/src/demuxers/demux_qt.c index ae657fb66..3fb60c1a8 100644 --- a/src/demuxers/demux_qt.c +++ b/src/demuxers/demux_qt.c @@ -1459,8 +1459,7 @@ static qt_error parse_trak_atom (qt_trak *trak, debug_atom_load(" qt stco atom (32-bit chunk offset atom): %d chunk offsets\n", trak->chunk_offset_count); - trak->chunk_offset_table = (int64_t *)malloc( - trak->chunk_offset_count * sizeof(int64_t)); + trak->chunk_offset_table = calloc(trak->chunk_offset_count, sizeof(int64_t)); if (!trak->chunk_offset_table) { last_error = QT_NO_MEMORY; goto free_trak; @@ -1487,8 +1486,7 @@ static qt_error parse_trak_atom (qt_trak *trak, debug_atom_load(" qt co64 atom (64-bit chunk offset atom): %d chunk offsets\n", trak->chunk_offset_count); - trak->chunk_offset_table = (int64_t *)malloc( - trak->chunk_offset_count * sizeof(int64_t)); + trak->chunk_offset_table = calloc(trak->chunk_offset_count, sizeof(int64_t)); if (!trak->chunk_offset_table) { last_error = QT_NO_MEMORY; goto free_trak; @@ -1518,8 +1516,7 @@ static qt_error parse_trak_atom (qt_trak *trak, debug_atom_load(" qt stsc atom (sample-to-chunk atom): %d entries\n", trak->sample_to_chunk_count); - trak->sample_to_chunk_table = (sample_to_chunk_table_t *)malloc( - trak->sample_to_chunk_count * sizeof(sample_to_chunk_table_t)); + trak->sample_to_chunk_table = calloc(trak->sample_to_chunk_count, sizeof(sample_to_chunk_table_t)); if (!trak->sample_to_chunk_table) { last_error = QT_NO_MEMORY; goto free_trak; @@ -1553,8 +1550,7 @@ static qt_error parse_trak_atom (qt_trak *trak, debug_atom_load(" qt stts atom (time-to-sample atom): %d entries\n", trak->time_to_sample_count); - trak->time_to_sample_table = (time_to_sample_table_t *)malloc( - (trak->time_to_sample_count+1) * sizeof(time_to_sample_table_t)); + trak->time_to_sample_table = calloc(trak->time_to_sample_count+1, sizeof(time_to_sample_table_t)); if (!trak->time_to_sample_table) { last_error = QT_NO_MEMORY; goto free_trak; @@ -1747,8 +1743,7 @@ static qt_error build_frame_table(qt_trak *trak, /* in this case, the total number of frames is equal to the number of * entries in the sample size table */ trak->frame_count = trak->sample_size_count; - trak->frames = (qt_frame *)malloc( - trak->frame_count * sizeof(qt_frame)); + trak->frames = calloc(trak->frame_count, sizeof(qt_frame)); if (!trak->frames) return QT_NO_MEMORY; trak->current_frame = 0; @@ -1760,10 +1755,9 @@ static qt_error build_frame_table(qt_trak *trak, pts_index_countdown = trak->time_to_sample_table[pts_index].count; - media_id_counts = xine_xmalloc(trak->stsd_atoms_count * sizeof(int)); + media_id_counts = xine_xcalloc(trak->stsd_atoms_count, sizeof(int)); if (!media_id_counts) return QT_NO_MEMORY; - memset(media_id_counts, 0, trak->stsd_atoms_count * sizeof(int)); /* iterate through each start chunk in the stsc table */ for (i = 0; i < trak->sample_to_chunk_count; i++) { @@ -1898,8 +1892,7 @@ static qt_error build_frame_table(qt_trak *trak, /* in this case, the total number of frames is equal to the number of * chunks */ trak->frame_count = trak->chunk_offset_count; - trak->frames = (qt_frame *)malloc( - trak->frame_count * sizeof(qt_frame)); + trak->frames = calloc(trak->frame_count, sizeof(qt_frame)); if (!trak->frames) return QT_NO_MEMORY; -- cgit v1.2.3 From 8e9cb121101b1b43f6b52cd01e3e0fb841c538c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 20:46:23 +0100 Subject: Allocate the preview buffer only when actually needed; use zeroed allocation rather than memset(). --- src/demuxers/demux_qt.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/demuxers') diff --git a/src/demuxers/demux_qt.c b/src/demuxers/demux_qt.c index 3fb60c1a8..8fb554de2 100644 --- a/src/demuxers/demux_qt.c +++ b/src/demuxers/demux_qt.c @@ -2134,7 +2134,6 @@ static qt_error open_qt_file(qt_info *info, input_plugin_t *input, unsigned char *moov_atom = NULL; off_t moov_atom_offset = -1; int64_t moov_atom_size = -1; - unsigned char preview[MAX_PREVIEW_SIZE]; /* zlib stuff */ z_stream z_state; @@ -2157,7 +2156,7 @@ static qt_error open_qt_file(qt_info *info, input_plugin_t *input, if ((input->get_capabilities(input) & INPUT_CAP_SEEKABLE)) find_moov_atom(input, &moov_atom_offset, &moov_atom_size); else { - memset (&preview, 0, MAX_PREVIEW_SIZE); + unsigned char preview[MAX_PREVIEW_SIZE] = { 0, }; input->get_optional_data(input, preview, INPUT_OPTIONAL_DATA_PREVIEW); if (_X_BE_32(&preview[4]) != MOOV_ATOM) { /* special case if there is an ftyp atom first */ -- cgit v1.2.3 From c03568412615ffb294650149c5f6de18288f0976 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 21:10:55 +0100 Subject: Set the values of buffers in the same if as they are tested. Use calloc(1, ...) rather than using memset right afterward. --- src/demuxers/asfheader.c | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) (limited to 'src/demuxers') diff --git a/src/demuxers/asfheader.c b/src/demuxers/asfheader.c index 26a61d8fd..35bd187df 100644 --- a/src/demuxers/asfheader.c +++ b/src/demuxers/asfheader.c @@ -130,8 +130,7 @@ static uint8_t *asf_reader_get_bytes(asf_reader_t *reader, size_t size) { if ((reader->size - reader->pos) < size) return NULL; - buffer = malloc(size); - if (!buffer) + if (! (buffer = malloc(size)) ) return NULL; memcpy(buffer, reader->buffer + reader->pos, size); reader->pos += size; @@ -241,8 +240,7 @@ static int asf_header_parse_file_properties(asf_header_t *header, uint8_t *buffe return 0; } - asf_file = malloc(sizeof(asf_file_t)); - if (!asf_file) { + if (! (asf_file = malloc(sizeof(asf_file_t))) ) { lprintf("cannot allocate asf_file_struct\n"); return 0; } @@ -296,8 +294,7 @@ static int asf_header_parse_stream_properties(asf_header_t *header, uint8_t *buf if (buffer_len < 54) goto exit_error; - asf_stream = malloc(sizeof(asf_stream_t)); - if (!asf_stream) + if (! (asf_stream = malloc(sizeof(asf_stream_t))) ) goto exit_error; asf_reader_init(&reader, buffer, buffer_len); @@ -363,8 +360,7 @@ static int asf_header_parse_stream_extended_properties(asf_header_t *header, uin if (buffer_len < 64) return 0; - asf_stream_extension = malloc(sizeof(asf_stream_extension_t)); - if (!asf_stream_extension) + if (! (asf_stream_extension = malloc(sizeof(asf_stream_extension_t))) ) return 0; asf_reader_init(&reader, buffer, buffer_len); @@ -581,10 +577,8 @@ static int asf_header_parse_content_description(asf_header_t *header_pub, uint8_ if (buffer_len < 10) return 0; - content = malloc(sizeof(asf_content_t)); - if (!content) + if (! (content = calloc(1, sizeof(asf_content_t))) ) return 0; - memset(content, 0, sizeof(asf_content_t)); asf_reader_init(&reader, buffer, buffer_len); asf_reader_get_16(&reader, &title_length); @@ -611,10 +605,8 @@ asf_header_t *asf_header_new (uint8_t *buffer, int buffer_len) { uint32_t object_count; uint16_t junk; - asf_header = malloc(sizeof(asf_header_internal_t)); - if (!asf_header) + if (! (asf_header = calloc(1, sizeof(asf_header_internal_t))) ) return NULL; - memset(asf_header, 0, sizeof(asf_header_internal_t)); lprintf("parsing_asf_header\n"); if (buffer_len < 6) { @@ -697,10 +689,8 @@ asf_header_t *asf_header_new (uint8_t *buffer, int buffer_len) { } if (!asf_header->pub.content) { lprintf("no content object present\n"); - asf_header->pub.content = malloc(sizeof(asf_content_t)); - if (!asf_header->pub.content) + if (! (asf_header->pub.content = calloc(1, sizeof(asf_content_t))) ) goto exit_error; - memset(asf_header->pub.content, 0, sizeof(asf_content_t)); } return &asf_header->pub; -- cgit v1.2.3 From de2319031060f7ac4e7e4c169944490e43539777 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 21:12:12 +0100 Subject: Check for buffer_len before allocating the buffer, so it hasn't to be freed. --- src/demuxers/asfheader.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/demuxers') diff --git a/src/demuxers/asfheader.c b/src/demuxers/asfheader.c index 35bd187df..720bf5423 100644 --- a/src/demuxers/asfheader.c +++ b/src/demuxers/asfheader.c @@ -605,16 +605,15 @@ asf_header_t *asf_header_new (uint8_t *buffer, int buffer_len) { uint32_t object_count; uint16_t junk; - if (! (asf_header = calloc(1, sizeof(asf_header_internal_t))) ) - return NULL; - lprintf("parsing_asf_header\n"); if (buffer_len < 6) { printf("invalid buffer size\n"); - free(asf_header); return NULL; } + if (! (asf_header = calloc(1, sizeof(asf_header_internal_t))) ) + return NULL; + asf_header->iconv_cd = iconv_open ("UTF-8", "UCS-2LE"); if (asf_header->iconv_cd == (iconv_t)-1) { printf("iconv open error\n"); -- cgit v1.2.3 From b3945e2e0132309fd2eaf583e4ad9c0245c7828e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 21:28:51 +0100 Subject: Only open (and close) iconv in asf_header_parse_content_description. This way the iconv descriptor is not left open during the whole ASF demuxing. --- src/demuxers/asfheader.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) (limited to 'src/demuxers') diff --git a/src/demuxers/asfheader.c b/src/demuxers/asfheader.c index 720bf5423..23692574e 100644 --- a/src/demuxers/asfheader.c +++ b/src/demuxers/asfheader.c @@ -63,7 +63,6 @@ struct asf_header_internal_s { /* private part */ int number_count; uint16_t numbers[ASF_MAX_NUM_STREAMS]; - iconv_t iconv_cd; uint8_t *bitrate_pointers[ASF_MAX_NUM_STREAMS]; }; @@ -573,6 +572,7 @@ static int asf_header_parse_content_description(asf_header_t *header_pub, uint8_ asf_reader_t reader; asf_content_t *content; uint16_t title_length, author_length, copyright_length, description_length, rating_length; + iconv_t iconv_cd; if (buffer_len < 10) return 0; @@ -580,6 +580,9 @@ static int asf_header_parse_content_description(asf_header_t *header_pub, uint8_ if (! (content = calloc(1, sizeof(asf_content_t))) ) return 0; + if ( (iconv_cd = iconv_open("UTF-8", "UCS-2LE")) == (iconv_t)-1 ) + return 0; + asf_reader_init(&reader, buffer, buffer_len); asf_reader_get_16(&reader, &title_length); asf_reader_get_16(&reader, &author_length); @@ -587,13 +590,15 @@ static int asf_header_parse_content_description(asf_header_t *header_pub, uint8_ asf_reader_get_16(&reader, &description_length); asf_reader_get_16(&reader, &rating_length); - content->title = asf_reader_get_string(&reader, title_length, header->iconv_cd); - content->author = asf_reader_get_string(&reader, author_length, header->iconv_cd); - content->copyright = asf_reader_get_string(&reader, copyright_length, header->iconv_cd); - content->description = asf_reader_get_string(&reader, description_length, header->iconv_cd); - content->rating = asf_reader_get_string(&reader, rating_length, header->iconv_cd); + content->title = asf_reader_get_string(&reader, title_length, iconv_cd); + content->author = asf_reader_get_string(&reader, author_length, iconv_cd); + content->copyright = asf_reader_get_string(&reader, copyright_length, iconv_cd); + content->description = asf_reader_get_string(&reader, description_length, iconv_cd); + content->rating = asf_reader_get_string(&reader, rating_length, iconv_cd); header->pub.content = content; + + iconv_close(iconv_cd); return 1; } @@ -614,13 +619,6 @@ asf_header_t *asf_header_new (uint8_t *buffer, int buffer_len) { if (! (asf_header = calloc(1, sizeof(asf_header_internal_t))) ) return NULL; - asf_header->iconv_cd = iconv_open ("UTF-8", "UCS-2LE"); - if (asf_header->iconv_cd == (iconv_t)-1) { - printf("iconv open error\n"); - free(asf_header); - return NULL; - } - asf_reader_init(&reader, buffer, buffer_len); asf_reader_get_32(&reader, &object_count); asf_reader_get_16(&reader, &junk); @@ -755,9 +753,6 @@ void asf_header_delete (asf_header_t *header_pub) { asf_header_delete_stream_extended_properties(header->pub.stream_extensions[i]); } - if (header->iconv_cd != (iconv_t)-1) - iconv_close (header->iconv_cd); - free(header); } -- cgit v1.2.3 From 081e91d5a7631867606609fae0cb861abd5586b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 21:31:09 +0100 Subject: Use an automatic array rather than malloc'ing and free'ing it on the function. --- src/demuxers/demux_asf.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/demuxers') diff --git a/src/demuxers/demux_asf.c b/src/demuxers/demux_asf.c index 889299beb..f5091035b 100644 --- a/src/demuxers/demux_asf.c +++ b/src/demuxers/demux_asf.c @@ -612,14 +612,14 @@ static int demux_asf_send_headers_common (demux_asf_t *this) { } static void asf_reorder(demux_asf_t *this, uint8_t *src, int len){ - uint8_t *dst = malloc(len); + uint8_t dst[len]; uint8_t *s2 = src; int i = 0, x, y; while(len-i >= this->reorder_h * this->reorder_w*this->reorder_b){ for(x = 0; x < this->reorder_w; x++) for(y = 0; y < this->reorder_h; y++){ - memcpy(dst + i, s2 + (y * this->reorder_w+x) * this->reorder_b, + memcpy(&dst[i], s2 + (y * this->reorder_w+x) * this->reorder_b, this->reorder_b); i += this->reorder_b; } @@ -627,7 +627,6 @@ static void asf_reorder(demux_asf_t *this, uint8_t *src, int len){ } xine_fast_memcpy(src,dst,i); - free(dst); } /* redefine abs as macro to handle 64-bit diffs. -- cgit v1.2.3 From 0014ed290612dfecaad2b16f030ee8808f60e1b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 21:33:34 +0100 Subject: There's no need to use an if: when block_data is NULL, realloc() acts as malloc(). --- src/demuxers/demux_matroska.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src/demuxers') diff --git a/src/demuxers/demux_matroska.c b/src/demuxers/demux_matroska.c index f8166173a..16cf87978 100644 --- a/src/demuxers/demux_matroska.c +++ b/src/demuxers/demux_matroska.c @@ -1749,10 +1749,7 @@ static int parse_tags(demux_matroska_t *this) { static void alloc_block_data (demux_matroska_t *this, int len) { /* memory management */ if (this->block_data_size < len) { - if (this->block_data) - this->block_data = realloc(this->block_data, len); - else - this->block_data = malloc(len); + this->block_data = realloc(this->block_data, len); this->block_data_size = len; } } -- cgit v1.2.3 From 528cbe3723dcdafc6eb80817721ea5cf6fb9b050 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 21:36:15 +0100 Subject: Use calloc() when allocating an array of elements. --- src/demuxers/demux_real.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/demuxers') diff --git a/src/demuxers/demux_real.c b/src/demuxers/demux_real.c index af74d979b..962030083 100644 --- a/src/demuxers/demux_real.c +++ b/src/demuxers/demux_real.c @@ -232,7 +232,7 @@ static void real_parse_index(demux_real_t *this) { if(index && entries) { /* Allocate memory for index */ - *index = xine_xmalloc(entries * sizeof(real_index_entry_t)); + *index = xine_xcalloc(entries, sizeof(real_index_entry_t)); /* Read index */ for(i = 0; i < entries; i++) { @@ -275,17 +275,17 @@ static mdpr_t *real_parse_mdpr(const char *data) { mdpr->duration=_X_BE_32(&data[28]); mdpr->stream_name_size=data[32]; - mdpr->stream_name=malloc(sizeof(char)*(mdpr->stream_name_size+1)); + mdpr->stream_name=calloc(mdpr->stream_name_size+1, sizeof(char)); memcpy(mdpr->stream_name, &data[33], mdpr->stream_name_size); mdpr->stream_name[(int)mdpr->stream_name_size]=0; mdpr->mime_type_size=data[33+mdpr->stream_name_size]; - mdpr->mime_type=malloc(sizeof(char)*(mdpr->mime_type_size+1)); + mdpr->mime_type=calloc(mdpr->mime_type_size+1, sizeof(char)); memcpy(mdpr->mime_type, &data[34+mdpr->stream_name_size], mdpr->mime_type_size); mdpr->mime_type[(int)mdpr->mime_type_size]=0; mdpr->type_specific_len=_X_BE_32(&data[34+mdpr->stream_name_size+mdpr->mime_type_size]); - mdpr->type_specific_data=malloc(sizeof(char)*(mdpr->type_specific_len)); + mdpr->type_specific_data=calloc(mdpr->type_specific_len, sizeof(char)); memcpy(mdpr->type_specific_data, &data[38+mdpr->stream_name_size+mdpr->mime_type_size], mdpr->type_specific_len); -- cgit v1.2.3 From e3ab135aff25bcb39f9d536784f08fb16945264a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 18 Dec 2007 21:38:21 +0100 Subject: Use automatic buffers rather than malloc/free the buffer. --- src/demuxers/id3.c | 30 +++--------------------------- 1 file changed, 3 insertions(+), 27 deletions(-) (limited to 'src/demuxers') diff --git a/src/demuxers/id3.c b/src/demuxers/id3.c index 4149c0512..ceb66014f 100644 --- a/src/demuxers/id3.c +++ b/src/demuxers/id3.c @@ -273,15 +273,9 @@ static int id3v22_parse_frame_header(input_plugin_t *input, static int id3v22_interp_frame(input_plugin_t *input, xine_stream_t *stream, id3v22_frame_header_t *frame_header) { - char *buf; + char buf[frame_header->size + 1]; int enc; - buf = malloc(frame_header->size + 1); - if (buf == NULL) { - lprintf("malloc error"); - return 0; - } - if (input->read (input, buf, frame_header->size) == frame_header->size) { buf[frame_header->size] = 0; enc = buf[0]; @@ -327,11 +321,9 @@ static int id3v22_interp_frame(input_plugin_t *input, lprintf("unhandled frame\n"); } - free(buf); return 1; } else { lprintf("read error\n"); - free(buf); return 0; } } @@ -467,15 +459,9 @@ static int id3v23_parse_frame_ext_header(input_plugin_t *input, static int id3v23_interp_frame(input_plugin_t *input, xine_stream_t *stream, id3v23_frame_header_t *frame_header) { - char *buf; + char buf[frame_header->size + 1]; int enc; - buf = malloc(frame_header->size + 1); - if (buf == NULL) { - lprintf("malloc error"); - return 0; - } - if (input->read (input, buf, frame_header->size) == frame_header->size) { buf[frame_header->size] = 0; enc = buf[0]; @@ -521,11 +507,9 @@ static int id3v23_interp_frame(input_plugin_t *input, lprintf("unhandled frame\n"); } - free(buf); return 1; } else { lprintf("read error\n"); - free(buf); return 0; } } @@ -716,15 +700,9 @@ static int id3v24_parse_ext_header(input_plugin_t *input, static int id3v24_interp_frame(input_plugin_t *input, xine_stream_t *stream, id3v24_frame_header_t *frame_header) { - char *buf; + char buf[frame_header->size + 1]; int enc; - buf = malloc(frame_header->size + 1); - if (buf == NULL) { - lprintf("malloc error"); - return 0; - } - if (input->read (input, buf, frame_header->size) == frame_header->size) { buf[frame_header->size] = 0; enc = buf[0]; @@ -772,11 +750,9 @@ static int id3v24_interp_frame(input_plugin_t *input, lprintf("unhandled frame\n"); } - free(buf); return 1; } else { lprintf("read error\n"); - free(buf); return 0; } } -- cgit v1.2.3