From b69b58a12addf08b435457b91e41512e748238d5 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Mon, 13 May 2024 21:36:36 +0200 Subject: [PATCH] {options,player}: fix stream leaks --- options/parse_configfile.c | 10 ++++++---- player/misc.c | 7 +++++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/options/parse_configfile.c b/options/parse_configfile.c index edd6be918c..f648f1b86b 100644 --- a/options/parse_configfile.c +++ b/options/parse_configfile.c @@ -163,16 +163,18 @@ int m_config_parse_config_file(m_config_t *config, struct mpv_global *global, MP_VERBOSE(config, "Reading config file %s\n", conffile); + int r = 0; + struct stream *s = stream_create(conffile, STREAM_READ | STREAM_ORIGIN_DIRECT, NULL, global); if (!s) - return 0; + goto done; bstr data = stream_read_complete(s, s, 1000000000); if (!data.start) - return 0; + goto done; + r = m_config_parse(config, conffile, data, initial_section, flags); - int r = m_config_parse(config, conffile, data, initial_section, flags); - talloc_free(data.start); +done: free_stream(s); return r; } diff --git a/player/misc.c b/player/misc.c index 1b265e11fa..a290899306 100644 --- a/player/misc.c +++ b/player/misc.c @@ -266,6 +266,8 @@ void error_on_track(struct MPContext *mpctx, struct track *track) int stream_dump(struct MPContext *mpctx, const char *source_filename) { struct MPOpts *opts = mpctx->opts; + bool ok = false; + stream_t *stream = stream_create(source_filename, STREAM_ORIGIN_DIRECT | STREAM_READ, mpctx->playback_abort, mpctx->global); @@ -277,10 +279,10 @@ int stream_dump(struct MPContext *mpctx, const char *source_filename) FILE *dest = fopen(opts->stream_dump, "wb"); if (!dest) { MP_ERR(mpctx, "Error opening dump file: %s\n", mp_strerror(errno)); - return -1; + goto done; } - bool ok = true; + ok = true; while (mpctx->stop_play == KEEP_PLAYING && ok) { if (!opts->quiet && ((stream->pos / (1024 * 1024)) % 2) == 1) { @@ -300,6 +302,7 @@ int stream_dump(struct MPContext *mpctx, const char *source_filename) } ok &= fclose(dest) == 0; +done: free_stream(stream); return ok ? 0 : -1; }