From patchwork Fri Nov 9 05:31:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 10958 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 1163C44D40E for ; Fri, 9 Nov 2018 07:33:07 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 72A85689E5C; Fri, 9 Nov 2018 07:32:38 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8EFBA689E51 for ; Fri, 9 Nov 2018 07:32:31 +0200 (EET) Received: by mail-wm1-f65.google.com with SMTP id r63-v6so825569wma.4 for ; Thu, 08 Nov 2018 21:33:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ocPDsWh5u8Wl2GbJ6G6mQkRtkxx/faBNjpJkSKPIYl8=; b=MslY/bYZwsHQfXfNu1zkptDbD5QdHg8COUqHUnWTgWfa1lRnMUfLYmrffWqNk0dC1R 8tUOBsEzdmqfOiZgMVGXag+vRPP0lk04kK50guc3eKlizq6UPSEq+dGNAJ4xMIIyStj5 nXLv6YoZp/kC1KQ7sGrQagU4KxnB4s6HN3B3yp/5t+pV6O661lnC1uOnqVl1nRZX7VZW cYHhHm12vu6sHLNt1wjB12YQQ55mZq7BFmD134w/y3/zJfOC731bD1kCW7iLSTGy0+z1 Yz4IxV+MFPISSKJGDdd1x9hdJDyuFDOvWVnrCfFp00f/H6Zrk9afNYmB3MWaIsnO80F0 ZV5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ocPDsWh5u8Wl2GbJ6G6mQkRtkxx/faBNjpJkSKPIYl8=; b=qtthS0Zy8elG4MzsVHJ9qFwUFFJzI8/kMdVeRzOQra7Kj4DG/iCWTZQXVlaxXzr3aI bEDECH+8OMmNECF/69gcay0V/9fMLNUuVIqBHTJ+ddlgofQkP39akvQHRG4x0MyuoTz5 k/9nC4hLpvW93QxeeNTrod//1DLlerMgppY+2wsDlLRIFqG8eFn6mqYxK8JVeEcHktA2 c2plDEo0jKozWUxHWwJk0wYmzpCx5TG1u2jL27QpM9jsRaEcKGQqTj3P3sNwXnRYhyd7 1VmmAPNrvnIgxfocJz0VQrGUL7rxUpUdTrqtuNcTSfr67l/jM/16nw0cAK060lujirLD adbA== X-Gm-Message-State: AGRZ1gJVOd8TZsDkiwy5CTEivjHTISVYfA1WzCBfr/O6ramfI2chZxA9 TqbPWZKYNq77lid6D3T/Of4fkRPc X-Google-Smtp-Source: AJdET5dAoSOFu+1kCUXzNgK6UscI3PU158d/MQTNSOvVaS6Ls/2siercIUHNUUAu+keVSazGZP5fLg== X-Received: by 2002:a1c:2e50:: with SMTP id u77-v6mr3593769wmu.106.1541741586573; Thu, 08 Nov 2018 21:33:06 -0800 (PST) Received: from localhost.localdomain (ipbcc08c44.dynamic.kabel-deutschland.de. [188.192.140.68]) by smtp.googlemail.com with ESMTPSA id l140-v6sm1098230wmb.24.2018.11.08.21.33.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Nov 2018 21:33:06 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 9 Nov 2018 06:31:36 +0100 Message-Id: <20181109053138.4572-5-andreas.rheinhardt@googlemail.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181109053138.4572-1-andreas.rheinhardt@googlemail.com> References: <20181109053138.4572-1-andreas.rheinhardt@googlemail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 4/6] h264_redundant_pps: Fix memleak in case of errors X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Now the fragment is uninitialized and the input packet freed in case of errors. Signed-off-by: Andreas Rheinhardt --- libavcodec/h264_redundant_pps_bsf.c | 46 ++++++++++++++++++----------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/libavcodec/h264_redundant_pps_bsf.c b/libavcodec/h264_redundant_pps_bsf.c index cc5a3060f5..79a11c0e30 100644 --- a/libavcodec/h264_redundant_pps_bsf.c +++ b/libavcodec/h264_redundant_pps_bsf.c @@ -76,11 +76,11 @@ static int h264_redundant_pps_filter(AVBSFContext *bsf, AVPacket *out) err = ff_bsf_get_packet(bsf, &in); if (err < 0) - return err; + goto fail; err = ff_cbs_read_packet(ctx->input, au, in); if (err < 0) - return err; + goto fail; au_has_sps = 0; for (i = 0; i < au->nb_units; i++) { @@ -89,11 +89,15 @@ static int h264_redundant_pps_filter(AVBSFContext *bsf, AVPacket *out) if (nal->type == H264_NAL_SPS) au_has_sps = 1; if (nal->type == H264_NAL_PPS) { - h264_redundant_pps_fixup_pps(ctx, nal->content); + err = h264_redundant_pps_fixup_pps(ctx, nal->content); + if (err < 0) + goto fail; if (!au_has_sps) { av_log(ctx, AV_LOG_VERBOSE, "Deleting redundant PPS " "at %"PRId64".\n", in->pts); - ff_cbs_delete_unit(ctx->input, au, i); + err = ff_cbs_delete_unit(ctx->input, au, i); + if (err < 0) + goto fail; } } if (nal->type == H264_NAL_SLICE || @@ -105,17 +109,21 @@ static int h264_redundant_pps_filter(AVBSFContext *bsf, AVPacket *out) err = ff_cbs_write_packet(ctx->output, out, au); if (err < 0) - return err; + goto fail; - ff_cbs_fragment_uninit(ctx->output, au); err = av_packet_copy_props(out, in); if (err < 0) - return err; + goto fail; + err = 0; +fail: + ff_cbs_fragment_uninit(ctx->output, au); av_packet_free(&in); + if (err < 0) + av_packet_unref(out); - return 0; + return err; } static int h264_redundant_pps_init(AVBSFContext *bsf) @@ -126,11 +134,11 @@ static int h264_redundant_pps_init(AVBSFContext *bsf) err = ff_cbs_init(&ctx->input, AV_CODEC_ID_H264, bsf); if (err < 0) - return err; + goto fail; err = ff_cbs_init(&ctx->output, AV_CODEC_ID_H264, bsf); if (err < 0) - return err; + goto fail; ctx->global_pic_init_qp = 26; @@ -138,25 +146,29 @@ static int h264_redundant_pps_init(AVBSFContext *bsf) err = ff_cbs_read_extradata(ctx->input, au, bsf->par_in); if (err < 0) { av_log(bsf, AV_LOG_ERROR, "Failed to read extradata.\n"); - return err; + goto fail; } for (i = 0; i < au->nb_units; i++) { - if (au->units[i].type == H264_NAL_PPS) - h264_redundant_pps_fixup_pps(ctx, au->units[i].content); + if (au->units[i].type == H264_NAL_PPS) { + err = h264_redundant_pps_fixup_pps(ctx, au->units[i].content); + if (err < 0) + goto fail; + } } ctx->extradata_pic_init_qp = ctx->current_pic_init_qp; err = ff_cbs_write_extradata(ctx->output, bsf->par_out, au); if (err < 0) { av_log(bsf, AV_LOG_ERROR, "Failed to write extradata.\n"); - return err; + goto fail; } - - ff_cbs_fragment_uninit(ctx->output, au); } - return 0; + err = 0; +fail: + ff_cbs_fragment_uninit(ctx->output, au); + return err; } static void h264_redundant_pps_flush(AVBSFContext *bsf)