From patchwork Wed Sep 5 08:53:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Zhili X-Patchwork-Id: 10236 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:12c4:0:0:0:0:0 with SMTP id 65-v6csp4871412jap; Wed, 5 Sep 2018 01:54:17 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYE2y9sanW5/t53fwNtjGsVk5oJvKuIhW7IPrREu6fgAOCDDja0zEmI2oYZZzqDK/FCmVAF X-Received: by 2002:a5d:6604:: with SMTP id n4-v6mr14593665wru.281.1536137657779; Wed, 05 Sep 2018 01:54:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536137657; cv=none; d=google.com; s=arc-20160816; b=DUgpElI+04Q0h4AE2Oqsg5oWWsHx5FKG+89BjzZKWQiQ9Wrq4l4EcM3/ieMRX8wDml KHfVOKogY095ju6At2gNt178Mx9rZfavJy0fLVW9tuUI/twMwao0ifgLfN8ujkoP70ET KtyJtiGu2PWIFRKymmSfUmo5gS7QVvOlGtXp3cQLVdGWSSfWLvsd1Bq+x81gQya7Unlm 9FglyyRkO6Y+4f4//KunFBCKICv7rTZ+Jpntx3szB2ncm4QwEuODic1we+zBSuROF/Ov CrcmnU7WY8JfqgHbWNdoEqvET9RrwTQAJXgyIhAvvjuwPDpmSHsewkznAdOja1C5kqsn gIGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:feedback-id:message-id:date:to:from :dkim-signature:delivered-to; bh=PZ7ANEjDMDTr+zy4s7bfQqoStm4Et6OlF9YlNohmZ5E=; b=HyDd4pUBJ5KjY9UwRTsi/xwEruEbvcuYWshnOQNmT0Chuw5RTujzE1Xyd+VNUtZUt9 0GmOz7mDcHvBNLaC65JnSTNdFN5psGiZqxwvgmwiXOrLAtrp4Uaa9zfyrlAytPpXI3QH 5zjhgMcUMLi5A7KxtP6pLSbNagu4QxcMS4unOUqFhNUEAZ8QvwUKa2Myhx6gafdXiHba o9dnXaWQEpkDESt/c1yKGMB9QVk9yDeC/v0uiGIlhuNzjDYV92UpAZQL+FSLg93rrGB9 KGP9ZpWpfLrdGqi53yoJAu8PC59VdG4qIaUA5XoKTjzkq7IloOmihdRD2s/nUkUPwakk 7SuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@foxmail.com header.s=s201512 header.b=NOvr+Co7; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=foxmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id w7-v6si1164210wru.330.2018.09.05.01.54.17; Wed, 05 Sep 2018 01:54:17 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@foxmail.com header.s=s201512 header.b=NOvr+Co7; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=foxmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2B910689F91; Wed, 5 Sep 2018 11:54:08 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from smtpbgau1.qq.com (smtpbgau1.qq.com [54.206.16.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id BA6DB680C09 for ; Wed, 5 Sep 2018 11:54:00 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1536137640; bh=OTOPe6yaT1hYdTymHrx+sC6sqjOnxvyl2xpa+NforIE=; h=From:To:Cc:Subject:Date:Message-Id; b=NOvr+Co7Wue2SfmMD6ZI1F7y439c8MpT/fSbpwe9pLcmMO2ekZyhaOIjIwaCghuvM Tx5/cVumZETmy5ykz620+amqKI0dsd2aufaighj6avmIr84cu+do7r0H5E0+ifwKS0 GhhBLLDfpASP41bw5q3O3ITgFtM+SmQfn8HrpNN4= X-QQ-mid: esmtp7t1536137639t45uk62sd Received: from localhost.localdomain (unknown [223.26.106.80]) by esmtp4.qq.com (ESMTP) with id ; Wed, 05 Sep 2018 16:53:48 +0800 (CST) X-QQ-SSF: A1000000000000F0F91100000000001 X-QQ-FEAT: OthLD3hRvFF9g769j4cyD5Z0m9jTFiRNEMoBy9KIDanwY2lixFb6pojz8r4cq ZvOGL7MVD5jwexki2KFYxhuwe05W8NZYVsGoU7OES68hPF22g2oU/pdH+Ucb1ks4+CI0O06 sKnsRhgxYa+XaZ92QINOQfmOlhCzGhzbsTDDQo2XdFx2+IBAS65JWLGF3JKd/UOyX/q8Wr4 a24y15xLbh1dGq9OHgF9R3LSLZHjOmO58zIop1G9EaN/wGXZNeYQn1/94391bsEKzAMVQZ2 Ezkf7gQ3pFPc2nu91iczB7sspVM8OGpQR7zw== X-QQ-GoodBg: 0 From: Zhao Zhili To: ffmpeg-devel@ffmpeg.org Date: Wed, 5 Sep 2018 16:53:44 +0800 Message-Id: <20180905085344.17678-1-quinkblack@foxmail.com> X-Mailer: git-send-email 2.9.5 X-QQ-SENDSIZE: 520 Feedback-ID: esmtp:foxmail.com:bgforeign:bgforeign2 X-QQ-Bgrelay: 1 Subject: [FFmpeg-devel] [PATCH] avcodec/h264dec: Fix init_context memleak on error path 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 Cc: Zhao Zhili MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" --- libavcodec/h264dec.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c index 8d115fa..b2447e9 100644 --- a/libavcodec/h264dec.c +++ b/libavcodec/h264dec.c @@ -303,6 +303,7 @@ fail: static int h264_init_context(AVCodecContext *avctx, H264Context *h) { int i; + int ret; h->avctx = avctx; h->cur_chroma_format_idc = -1; @@ -337,22 +338,37 @@ static int h264_init_context(AVCodecContext *avctx, H264Context *h) for (i = 0; i < H264_MAX_PICTURE_COUNT; i++) { h->DPB[i].f = av_frame_alloc(); - if (!h->DPB[i].f) - return AVERROR(ENOMEM); + if (!h->DPB[i].f) { + ret = AVERROR(ENOMEM); + goto fail; + } } h->cur_pic.f = av_frame_alloc(); - if (!h->cur_pic.f) - return AVERROR(ENOMEM); + if (!h->cur_pic.f) { + ret = AVERROR(ENOMEM); + goto fail; + } h->last_pic_for_ec.f = av_frame_alloc(); - if (!h->last_pic_for_ec.f) - return AVERROR(ENOMEM); + if (!h->last_pic_for_ec.f) { + ret = AVERROR(ENOMEM); + goto fail; + } for (i = 0; i < h->nb_slice_ctx; i++) h->slice_ctx[i].h264 = h; return 0; + +fail: + h->nb_slice_ctx = 0; + av_freep(&h->slice_ctx); + for (i = 0; i < H264_MAX_PICTURE_COUNT; i++) { + av_frame_free(&h->DPB[i].f); + } + av_frame_free(&h->cur_pic.f); + return ret; } static av_cold int h264_decode_end(AVCodecContext *avctx)