diff mbox

[FFmpeg-devel,2/2] ffmpeg: fix memleak of bitstream filter context on failure

Message ID 20160924182433.9160-2-jamrial@gmail.com
State Accepted
Commit 449dc25f56fa1a84285e0f972849c4c40896807b
Headers show

Commit Message

James Almer Sept. 24, 2016, 6:24 p.m. UTC
Increase the nb_bitstream_filters value as soon as the context is allocated, so
if option parsing fails the last context is actually freed.

Signed-off-by: James Almer <jamrial@gmail.com>
---
 ffmpeg_opt.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

Josh Dekker Sept. 25, 2016, 12:29 a.m. UTC | #1
On 24/09/2016 19:24, James Almer wrote:
> [...]

Both patches look good to me.

--
Josh
James Almer Sept. 25, 2016, 7:19 p.m. UTC | #2
On 9/24/2016 9:29 PM, Josh de Kock wrote:
> On 24/09/2016 19:24, James Almer wrote:
>> [...]
> 
> Both patches look good to me.
> 
> -- 
> Josh

Pushed, thanks.
diff mbox

Patch

diff --git a/ffmpeg_opt.c b/ffmpeg_opt.c
index 0dfdbd6..40a5090 100644
--- a/ffmpeg_opt.c
+++ b/ffmpeg_opt.c
@@ -1349,14 +1349,16 @@  static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e
             exit_program(1);
         }
 
+        ost->nb_bitstream_filters++;
+
         if (bsf_options_str && filter->priv_class) {
-            const AVOption *opt = av_opt_next(ost->bsf_ctx[ost->nb_bitstream_filters]->priv_data, NULL);
+            const AVOption *opt = av_opt_next(ost->bsf_ctx[ost->nb_bitstream_filters-1]->priv_data, NULL);
             const char * shorthand[2] = {NULL};
 
             if (opt)
                 shorthand[0] = opt->name;
 
-            ret = av_opt_set_from_string(ost->bsf_ctx[ost->nb_bitstream_filters]->priv_data, bsf_options_str, shorthand, "=", ":");
+            ret = av_opt_set_from_string(ost->bsf_ctx[ost->nb_bitstream_filters-1]->priv_data, bsf_options_str, shorthand, "=", ":");
             if (ret < 0) {
                 av_log(NULL, AV_LOG_ERROR, "Error parsing options for bitstream filter %s\n", bsf_name);
                 exit_program(1);
@@ -1364,8 +1366,6 @@  static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e
         }
         av_freep(&bsf);
 
-        ost->nb_bitstream_filters++;
-
         if (*bsfs)
             bsfs++;
     }