From patchwork Wed Sep 11 22:18:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 15032 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 355004482E2 for ; Thu, 12 Sep 2019 01:18:55 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0DAF4687F32; Thu, 12 Sep 2019 01:18:55 +0300 (EEST) 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 26276680234 for ; Thu, 12 Sep 2019 01:18:49 +0300 (EEST) Received: by mail-wm1-f65.google.com with SMTP id g207so5205477wmg.5 for ; Wed, 11 Sep 2019 15:18:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=vDzwpTGTz0qrKMLNDQD+7Gwhcn6ea0Ap2Ab9HYz2xrc=; b=X6L3vZbZRmUV/mlmULPZOOPLmvZTrultr5OXJhFXRq/xZopkfQufiWW8g8K7o+5HSR 9pmrbqwUXa3h5UWGgOJvOzf8/CInnIGp9Z54DX+zkK8ahpDUgeR/OwTRaQWhd8YZRaie uHjqt5zEkXx0tuko94c6nfTCF7r6LuPvGj/nhufraLnhBEsnWMY90fu65/vcgTW/OfQp qqmA/zWYl/tEUL0sCxSnZPBn2lpAWYB15fjkrCYuiqDSPuo7YDmCbNdYy5kUu35VGnz9 ztNHjOXp0TsCpEi9X0fRHiLLT6nhnaEU4nDyDB/OfQUHtHiAR3kLW1/DHvjxoYMQi/Pb FJ4Q== 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:mime-version :content-transfer-encoding; bh=vDzwpTGTz0qrKMLNDQD+7Gwhcn6ea0Ap2Ab9HYz2xrc=; b=CRfBo9mXvzYAoZ/bLR7r1i2nwQ63noFyFW0b8u0DxFoLS9di2rXq2L6unUs6Oz3Uhp rrZHcdQxnGsM/T+5VpDcBcQ2Fg9vAT9r5PMMnhfGouFoTJ9QyuRsrx2nfj7hRAtNpmFR Ot8IvQUkYKzfNnBycc4c0p6tZegdTCXczOs712QNn65eMWHUGQMwadeCehpf/Ku08m0W 2onmx78E/uB6CQcqU1EbrgdaeCo2lsQgYEfKsKuVPyouO9kmLQ0DdSLBadXtm6dXO/Rc ptABTMMv3gerkrCGp5dJzxOC9xvFnImQwg1tDpUCBXQ0tUvLZ7Ff9NjR1y0V5DJTx70m BA7A== X-Gm-Message-State: APjAAAWXTQTbgiahJ+rv//LvoG44U94UUqCi9zNjt+FaYZZv8Z16oQ6C Z5YYVjSzkMAyULJiukkz6ZVia14EEpw= X-Google-Smtp-Source: APXvYqwGJH/UZlKDRi6pktXPAetf97/K8xZgmhxGdCy0pgyFWDp1e+HqD2kG2qeRvC7urdvT6Kd6NA== X-Received: by 2002:a1c:9d0b:: with SMTP id g11mr5475863wme.22.1568240328087; Wed, 11 Sep 2019 15:18:48 -0700 (PDT) Received: from localhost.localdomain (ipbcc0f857.dynamic.kabel-deutschland.de. [188.192.248.87]) by smtp.gmail.com with ESMTPSA id 189sm6464388wma.6.2019.09.11.15.18.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2019 15:18:47 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 12 Sep 2019 00:18:29 +0200 Message-Id: <20190911221830.61819-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/2] avcodec/cbs_h264: Automatically free SEI payload on error 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" If adding an SEI message to an access unit fails, said SEI message was not touched, so that the caller had to free any data associated with it that might need to be freed. But given that ff_cbs_h264_add_sei_message can simply call cbs_h264_free_sei_payload, one can easily free the content of the SEI payload. This fixes a memleak when inserting a user data unregistered string for h264_metadata fails. Signed-off-by: Andreas Rheinhardt --- libavcodec/cbs_h264.h | 5 ++++- libavcodec/cbs_h2645.c | 16 +++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/libavcodec/cbs_h264.h b/libavcodec/cbs_h264.h index b39e7480c9..9f7c2a0d30 100644 --- a/libavcodec/cbs_h264.h +++ b/libavcodec/cbs_h264.h @@ -468,10 +468,13 @@ typedef struct CodedBitstreamH264Context { /** * Add an SEI message to an access unit. + * + * On success, the payload will be owned by a unit in access_unit; + * on failure, the content of the payload will be freed. */ int ff_cbs_h264_add_sei_message(CodedBitstreamContext *ctx, CodedBitstreamFragment *access_unit, - const H264RawSEIPayload *payload); + H264RawSEIPayload *payload); /** * Delete an SEI message from an access unit. diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c index 8da8421e47..2dc261f7a5 100644 --- a/libavcodec/cbs_h2645.c +++ b/libavcodec/cbs_h2645.c @@ -1586,7 +1586,7 @@ const CodedBitstreamType ff_cbs_type_h265 = { int ff_cbs_h264_add_sei_message(CodedBitstreamContext *ctx, CodedBitstreamFragment *au, - const H264RawSEIPayload *payload) + H264RawSEIPayload *payload) { H264RawSEI *sei = NULL; int err, i; @@ -1608,8 +1608,10 @@ int ff_cbs_h264_add_sei_message(CodedBitstreamContext *ctx, AVBufferRef *sei_ref; sei = av_mallocz(sizeof(*sei)); - if (!sei) - return AVERROR(ENOMEM); + if (!sei) { + err = AVERROR(ENOMEM); + goto fail; + } sei->nal_unit_header.nal_unit_type = H264_NAL_SEI; sei->nal_unit_header.nal_ref_idc = 0; @@ -1618,7 +1620,8 @@ int ff_cbs_h264_add_sei_message(CodedBitstreamContext *ctx, &cbs_h264_free_sei, NULL, 0); if (!sei_ref) { av_freep(&sei); - return AVERROR(ENOMEM); + err = AVERROR(ENOMEM); + goto fail; } for (i = 0; i < au->nb_units; i++) { @@ -1631,13 +1634,16 @@ int ff_cbs_h264_add_sei_message(CodedBitstreamContext *ctx, sei, sei_ref); av_buffer_unref(&sei_ref); if (err < 0) - return err; + goto fail; } memcpy(&sei->payload[sei->payload_count], payload, sizeof(*payload)); ++sei->payload_count; return 0; +fail: + cbs_h264_free_sei_payload(payload); + return err; } void ff_cbs_h264_delete_sei_message(CodedBitstreamContext *ctx,