From 8d1c7ca2065444dfe2da432a30c95782e3ead48d Mon Sep 17 00:00:00 2001 From: oblique Date: Sun, 3 Jul 2011 14:54:56 +0200 Subject: ffmpeg: workaround for semantic API change in recent ffmpeg versions --- src/decoder/ffmpeg_decoder_plugin.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/decoder/ffmpeg_decoder_plugin.c b/src/decoder/ffmpeg_decoder_plugin.c index 6d794db49..156853faf 100644 --- a/src/decoder/ffmpeg_decoder_plugin.c +++ b/src/decoder/ffmpeg_decoder_plugin.c @@ -321,7 +321,7 @@ ffmpeg_decode(struct decoder *decoder, struct input_stream *input) } //ffmpeg works with ours "fileops" helper - AVFormatContext *format_context; + AVFormatContext *format_context = NULL; if (av_open_input_stream(&format_context, stream->io, input->uri, input_format, NULL) != 0) { g_warning("Open failed\n"); @@ -470,7 +470,7 @@ ffmpeg_stream_tag(struct input_stream *is) if (stream == NULL) return NULL; - AVFormatContext *f; + AVFormatContext *f = NULL; if (av_open_input_stream(&f, stream->io, is->uri, input_format, NULL) != 0) { mpd_ffmpeg_stream_close(stream); -- cgit v1.2.3 From 6aa6a9c2727c863239d6396a40a781e98e922565 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 3 Jul 2011 14:57:56 +0200 Subject: decoder/flac: validate the sample rate when scanning the tag Don't calculate the song duration when the sample rate is 0 (division by zero crash). --- src/decoder/flac_metadata.c | 3 ++- src/decoder/flac_metadata.h | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/decoder/flac_metadata.c b/src/decoder/flac_metadata.c index f2f2f954d..5b94fd426 100644 --- a/src/decoder/flac_metadata.c +++ b/src/decoder/flac_metadata.c @@ -224,7 +224,8 @@ flac_tag_apply_metadata(struct tag *tag, const char *track, break; case FLAC__METADATA_TYPE_STREAMINFO: - tag->time = flac_duration(&block->data.stream_info); + if (block->data.stream_info.sample_rate > 0) + tag->time = flac_duration(&block->data.stream_info); break; default: diff --git a/src/decoder/flac_metadata.h b/src/decoder/flac_metadata.h index 06e691d1d..e52b0fb82 100644 --- a/src/decoder/flac_metadata.h +++ b/src/decoder/flac_metadata.h @@ -20,6 +20,7 @@ #ifndef MPD_FLAC_METADATA_H #define MPD_FLAC_METADATA_H +#include #include #include @@ -29,6 +30,8 @@ struct replay_gain_info; static inline unsigned flac_duration(const FLAC__StreamMetadata_StreamInfo *stream_info) { + assert(stream_info->sample_rate > 0); + return (stream_info->total_samples + stream_info->sample_rate - 1) / stream_info->sample_rate; } -- cgit v1.2.3 From affb4bd923492913ffebb71c4f977a6bbf9ed257 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Neusch=C3=A4fer?= Date: Mon, 18 Jul 2011 12:37:25 +0200 Subject: ape: add missing g_free in error path --- src/ape.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/ape.c b/src/ape.c index 5fca98e28..5f4da3f2e 100644 --- a/src/ape.c +++ b/src/ape.c @@ -60,8 +60,10 @@ ape_scan_internal(FILE *fp, tag_ape_callback_t callback, void *ctx) assert(remaining > 10); char *buffer = g_malloc(remaining); - if (fread(buffer, 1, remaining, fp) != remaining) + if (fread(buffer, 1, remaining, fp) != remaining) { + g_free(buffer); return false; + } /* read tags */ unsigned n = GUINT32_FROM_LE(footer.count); -- cgit v1.2.3 From d5684f74440fec77b3bc7c80a8396c79e4e489ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Neusch=C3=A4fer?= Date: Mon, 18 Jul 2011 12:47:06 +0200 Subject: sticker: fix a memory leak --- src/sticker.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/sticker.c b/src/sticker.c index c59cdd078..f6cd04346 100644 --- a/src/sticker.c +++ b/src/sticker.c @@ -579,8 +579,10 @@ sticker_load(const char *type, const char *uri) bool success; success = sticker_list_values(sticker->table, type, uri); - if (!success) + if (!success) { + sticker_free(sticker); return NULL; + } if (g_hash_table_size(sticker->table) == 0) { /* don't return empty sticker objects */ -- cgit v1.2.3 From c49c69d6ea0b7670f70066f0735fcffc69966d46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Neusch=C3=A4fer?= Date: Mon, 18 Jul 2011 12:38:43 +0200 Subject: conf: add missing fclose in error path This patch seems a bit ugly, maybe it would be a bit cleaner with gotos. --- src/conf.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/conf.c b/src/conf.c index 705942085..14dac93a6 100644 --- a/src/conf.c +++ b/src/conf.c @@ -367,6 +367,7 @@ config_read_file(const char *file, GError **error_r) assert(*line != 0); g_propagate_prefixed_error(error_r, error, "line %i: ", count); + fclose(fp); return false; } @@ -378,6 +379,7 @@ config_read_file(const char *file, GError **error_r) g_set_error(error_r, config_quark(), 0, "unrecognized parameter in config file at " "line %i: %s\n", count, name); + fclose(fp); return false; } @@ -387,6 +389,7 @@ config_read_file(const char *file, GError **error_r) "config parameter \"%s\" is first defined " "on line %i and redefined on line %i\n", name, param->line, count); + fclose(fp); return false; } @@ -398,6 +401,7 @@ config_read_file(const char *file, GError **error_r) if (*line != '{') { g_set_error(error_r, config_quark(), 0, "line %i: '{' expected", count); + fclose(fp); return false; } @@ -406,12 +410,15 @@ config_read_file(const char *file, GError **error_r) g_set_error(error_r, config_quark(), 0, "line %i: Unknown tokens after '{'", count); + fclose(fp); return false; } param = config_read_block(fp, &count, string, error_r); - if (param == NULL) + if (param == NULL) { + fclose(fp); return false; + } } else { /* a string value */ @@ -428,6 +435,7 @@ config_read_file(const char *file, GError **error_r) g_error_free(error); } + fclose(fp); return false; } @@ -435,6 +443,7 @@ config_read_file(const char *file, GError **error_r) g_set_error(error_r, config_quark(), 0, "line %i: Unknown tokens after value", count); + fclose(fp); return false; } -- cgit v1.2.3 From 36aa8ce3c9f34d41aa7fd94d90f23ba62f5caafb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Neusch=C3=A4fer?= Date: Mon, 18 Jul 2011 13:38:46 +0200 Subject: output/ao: add missing g_free in error path --- src/output/ao_plugin.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src') diff --git a/src/output/ao_plugin.c b/src/output/ao_plugin.c index 6fedbc6e2..42ece5a3a 100644 --- a/src/output/ao_plugin.c +++ b/src/output/ao_plugin.c @@ -106,12 +106,14 @@ ao_output_init(G_GNUC_UNUSED const struct audio_format *audio_format, g_set_error(error, ao_output_quark(), 0, "\"%s\" is not a valid ao driver", value); + g_free(ad); return NULL; } if ((ai = ao_driver_info(ad->driver)) == NULL) { g_set_error(error, ao_output_quark(), 0, "problems getting driver info"); + g_free(ad); return NULL; } @@ -129,6 +131,7 @@ ao_output_init(G_GNUC_UNUSED const struct audio_format *audio_format, g_set_error(error, ao_output_quark(), 0, "problems parsing options \"%s\"", options[i]); + g_free(ad); return NULL; } -- cgit v1.2.3 From 296085ff23f3992f0f45fc0325c5bdbab953e114 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Neusch=C3=A4fer?= Date: Mon, 18 Jul 2011 14:35:04 +0200 Subject: output/httpd: add missing g_free in error path --- src/output/httpd_output_plugin.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/output/httpd_output_plugin.c b/src/output/httpd_output_plugin.c index 6650d89e3..b82dc0599 100644 --- a/src/output/httpd_output_plugin.c +++ b/src/output/httpd_output_plugin.c @@ -103,6 +103,7 @@ httpd_output_init(G_GNUC_UNUSED const struct audio_format *audio_format, if (encoder_plugin == NULL) { g_set_error(error, httpd_output_quark(), 0, "No such encoder: %s", encoder_name); + g_free(httpd); return NULL; } -- cgit v1.2.3 From a6a8bdffc35c3b592ca9eb908ef010a27ddbb3ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Neusch=C3=A4fer?= Date: Mon, 18 Jul 2011 15:39:19 +0200 Subject: output/recorder: fix a memory leak --- src/output/recorder_output_plugin.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/output/recorder_output_plugin.c b/src/output/recorder_output_plugin.c index c01d927c4..10d64106c 100644 --- a/src/output/recorder_output_plugin.c +++ b/src/output/recorder_output_plugin.c @@ -79,23 +79,27 @@ recorder_output_init(G_GNUC_UNUSED const struct audio_format *audio_format, if (encoder_plugin == NULL) { g_set_error(error_r, recorder_output_quark(), 0, "No such encoder: %s", encoder_name); - return NULL; + goto failure; } recorder->path = config_get_block_string(param, "path", NULL); if (recorder->path == NULL) { g_set_error(error_r, recorder_output_quark(), 0, "'path' not configured"); - return NULL; + goto failure; } /* initialize encoder */ recorder->encoder = encoder_init(encoder_plugin, param, error_r); if (recorder->encoder == NULL) - return NULL; + goto failure; return recorder; + +failure: + g_free(recorder); + return NULL; } static void -- cgit v1.2.3 From 7d6a605a859139dd1e22b6e7e91479b644d5f398 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Neusch=C3=A4fer?= Date: Mon, 18 Jul 2011 15:58:02 +0200 Subject: output/shout: fix a memory leak --- src/output/shout_plugin.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/output/shout_plugin.c b/src/output/shout_plugin.c index baaeccf92..5e1ef762a 100644 --- a/src/output/shout_plugin.c +++ b/src/output/shout_plugin.c @@ -152,7 +152,7 @@ my_shout_init_driver(const struct audio_format *audio_format, if (port == 0) { g_set_error(error, shout_output_quark(), 0, "shout port must be configured"); - return NULL; + goto failure; } check_block_param("password"); @@ -174,21 +174,21 @@ my_shout_init_driver(const struct audio_format *audio_format, "shout quality \"%s\" is not a number in the " "range -1 to 10, line %i", value, param->line); - return NULL; + goto failure; } if (config_get_block_string(param, "bitrate", NULL) != NULL) { g_set_error(error, shout_output_quark(), 0, "quality and bitrate are " "both defined"); - return NULL; + goto failure; } } else { value = config_get_block_string(param, "bitrate", NULL); if (value == NULL) { g_set_error(error, shout_output_quark(), 0, "neither bitrate nor quality defined"); - return NULL; + goto failure; } sd->bitrate = strtol(value, &test, 10); @@ -196,7 +196,7 @@ my_shout_init_driver(const struct audio_format *audio_format, if (*test != '\0' || sd->bitrate <= 0) { g_set_error(error, shout_output_quark(), 0, "bitrate must be a positive integer"); - return NULL; + goto failure; } } @@ -206,12 +206,12 @@ my_shout_init_driver(const struct audio_format *audio_format, g_set_error(error, shout_output_quark(), 0, "couldn't find shout encoder plugin \"%s\"", encoding); - return NULL; + goto failure; } sd->encoder = encoder_init(encoder_plugin, param, error); if (sd->encoder == NULL) - return NULL; + goto failure; if (strcmp(encoding, "mp3") == 0 || strcmp(encoding, "lame") == 0) shout_format = SHOUT_FORMAT_MP3; @@ -225,7 +225,7 @@ my_shout_init_driver(const struct audio_format *audio_format, g_set_error(error, shout_output_quark(), 0, "you cannot stream \"%s\" to shoutcast, use mp3", encoding); - return NULL; + goto failure; } else if (0 == strcmp(value, "shoutcast")) protocol = SHOUT_PROTOCOL_ICY; else if (0 == strcmp(value, "icecast1")) @@ -237,7 +237,7 @@ my_shout_init_driver(const struct audio_format *audio_format, "shout protocol \"%s\" is not \"shoutcast\" or " "\"icecast1\"or \"icecast2\"", value); - return NULL; + goto failure; } } else { protocol = SHOUT_PROTOCOL_HTTP; @@ -256,7 +256,7 @@ my_shout_init_driver(const struct audio_format *audio_format, shout_set_agent(sd->shout_conn, "MPD") != SHOUTERR_SUCCESS) { g_set_error(error, shout_output_quark(), 0, "%s", shout_get_error(sd->shout_conn)); - return NULL; + goto failure; } /* optional paramters */ @@ -267,14 +267,14 @@ my_shout_init_driver(const struct audio_format *audio_format, if (value != NULL && shout_set_genre(sd->shout_conn, value)) { g_set_error(error, shout_output_quark(), 0, "%s", shout_get_error(sd->shout_conn)); - return NULL; + goto failure; } value = config_get_block_string(param, "description", NULL); if (value != NULL && shout_set_description(sd->shout_conn, value)) { g_set_error(error, shout_output_quark(), 0, "%s", shout_get_error(sd->shout_conn)); - return NULL; + goto failure; } { @@ -300,6 +300,10 @@ my_shout_init_driver(const struct audio_format *audio_format, } return sd; + +failure: + free_shout_data(sd); + return NULL; } static bool -- cgit v1.2.3 From 762712c756fe3041cc60cc4084ef505e56acf57c Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 8 Jul 2011 21:20:38 +0200 Subject: database: require X_OK on parent directory, not R_OK For accessing the child of a directory, one needs X_OK on the directory. --- src/database.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/database.c b/src/database.c index f255d6ca5..9f29f95e1 100644 --- a/src/database.c +++ b/src/database.c @@ -180,7 +180,7 @@ db_check(void) } /* Check if we can write to the directory */ - if (access(dirPath, R_OK | W_OK)) { + if (access(dirPath, X_OK | W_OK)) { g_warning("Can't create db file in \"%s\": %s", dirPath, strerror(errno)); g_free(dirPath); -- cgit v1.2.3 From 6592ca9f8805c3cf5154626087a01a183c38b6d5 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 18 Jul 2011 23:29:42 +0200 Subject: decoder: use AVDictionary instead of AVMetadata AVMetadata has been deprecated. --- src/decoder/ffmpeg_decoder_plugin.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/decoder/ffmpeg_decoder_plugin.c b/src/decoder/ffmpeg_decoder_plugin.c index 156853faf..15ea77f70 100644 --- a/src/decoder/ffmpeg_decoder_plugin.c +++ b/src/decoder/ffmpeg_decoder_plugin.c @@ -446,13 +446,26 @@ static const ffmpeg_tag_map ffmpeg_tag_maps[] = { }; static bool -ffmpeg_copy_metadata(struct tag *tag, AVMetadata *m, +ffmpeg_copy_metadata(struct tag *tag, +#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53,1,0) + AVDictionary *m, +#else + AVMetadata *m, +#endif const ffmpeg_tag_map tag_map) { +#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53,1,0) + AVDictionaryEntry *mt = NULL; + + while ((mt = av_dict_get(m, tag_map.name, mt, 0)) != NULL) + tag_add_item(tag, tag_map.type, mt->value); +#else AVMetadataTag *mt = NULL; while ((mt = av_metadata_get(m, tag_map.name, mt, 0)) != NULL) tag_add_item(tag, tag_map.type, mt->value); +#endif + return mt != NULL; } -- cgit v1.2.3 From 736fd0e29326548152e91e4e3fb8c0ea9c1b50ac Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 18 Jul 2011 23:31:47 +0200 Subject: decoder/ffmpeg: use avformat_open_input() if available av_open_input_stream() has been deprecated. --- src/decoder/ffmpeg_decoder_plugin.c | 39 +++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/decoder/ffmpeg_decoder_plugin.c b/src/decoder/ffmpeg_decoder_plugin.c index 15ea77f70..70628df9d 100644 --- a/src/decoder/ffmpeg_decoder_plugin.c +++ b/src/decoder/ffmpeg_decoder_plugin.c @@ -89,7 +89,11 @@ struct mpd_ffmpeg_stream { struct decoder *decoder; struct input_stream *input; +#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(52,101,0) + AVIOContext *io; +#else ByteIOContext *io; +#endif unsigned char buffer[8192]; }; @@ -135,6 +139,33 @@ mpd_ffmpeg_stream_open(struct decoder *decoder, struct input_stream *input) return stream; } +/** + * API compatibility wrapper for av_open_input_stream() and + * avformat_open_input(). + */ +static int +mpd_ffmpeg_open_input(AVFormatContext **ic_ptr, +#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(52,101,0) + AVIOContext *pb, +#else + ByteIOContext *pb, +#endif + const char *filename, + AVInputFormat *fmt) +{ +#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(53,1,3) + AVFormatContext *context = avformat_alloc_context(); + if (context == NULL) + return AVERROR(ENOMEM); + + context->pb = pb; + *ic_ptr = context; + return avformat_open_input(ic_ptr, filename, fmt, NULL); +#else + return av_open_input_stream(ic_ptr, pb, filename, fmt, NULL); +#endif +} + static void mpd_ffmpeg_stream_close(struct mpd_ffmpeg_stream *stream) { @@ -322,8 +353,8 @@ ffmpeg_decode(struct decoder *decoder, struct input_stream *input) //ffmpeg works with ours "fileops" helper AVFormatContext *format_context = NULL; - if (av_open_input_stream(&format_context, stream->io, input->uri, - input_format, NULL) != 0) { + if (mpd_ffmpeg_open_input(&format_context, stream->io, input->uri, + input_format) != 0) { g_warning("Open failed\n"); mpd_ffmpeg_stream_close(stream); return; @@ -484,8 +515,8 @@ ffmpeg_stream_tag(struct input_stream *is) return NULL; AVFormatContext *f = NULL; - if (av_open_input_stream(&f, stream->io, is->uri, - input_format, NULL) != 0) { + if (mpd_ffmpeg_open_input(&f, stream->io, is->uri, + input_format) != 0) { mpd_ffmpeg_stream_close(stream); return NULL; } -- cgit v1.2.3