From patchwork Wed Oct 23 12:59:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 15918 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 39D3944A928 for ; Wed, 23 Oct 2019 16:07:18 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2414868AE8F; Wed, 23 Oct 2019 16:07:18 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A694268AE5E for ; Wed, 23 Oct 2019 16:07:10 +0300 (EEST) Received: by mail-wm1-f67.google.com with SMTP id f22so19613631wmc.2 for ; Wed, 23 Oct 2019 06:07:10 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=lgSNazKK7kTGGXE19xrIwv/Stk7QeClgYHw8bpbiygA=; b=KzznUM2cEnX3NvY2Wby+M+Orl1v7fp9tjNcJPoU0R2tyOUCpOLVZ0HoyunOSKZw8XM GL9dX7foNVo0LIhL3XwUhT9gOO1Ccoysbq9x5m/qTWHbfVuzOCcw/QJKAcgzbZ2cqZuP MDRXVxEzyUiiH66dLN8SZJm5WJghyVkf0M/l6cMvnWH9tFynDaJtQ+cMfdR+in2M+M5P c8FQO8nurPbzBp31JkLTRFTtFZTw+ry7qU7Szqtu5elB+GZ5aqcMmn65j3B0EQ8iAPLA PzI9Qugnbmy/gxB3h+6eubDYmtsMCV8YHcNlVqnNjtqyqbUJzyhvfEdpfQS0BpAceH6U znXg== 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=lgSNazKK7kTGGXE19xrIwv/Stk7QeClgYHw8bpbiygA=; b=o/QRrFOJCMCJ+FGopJAt5XpWYlz+V8UwHX78togpzp5CtXMdBeLU7HA8HR59/SegAq 8s6XLdCSMFADv+5QRMIWVLc4RtXdGX7vzXMbLuN52N6tPwX1Snk7IGp/Lqs9vh/zdTQz AJx3aJ9ZsaTuey0pNoKLmtc+kDakhcnZmuXewANcmT2gI4LFRSzHchUXDw8LadvvP4c9 PeTSYuDNVF8PCdTSu/CibSUqIDnxCyc+oRUfY2tuUQJYR/q9+3N6aj3nURs/3HUAA2Ys o2pbiOv3rB+PFBz0iwiF/QwIwrCFFnPT+7BDrwjHffeLoHsxV3PBJJsnKo35TTAAbMIf pLWg== X-Gm-Message-State: APjAAAWKCO41k27kXOkc3HgTh00iU4sJhxYHdfMZ0cNNge8YK35DeHLf C/P1xwCpaOztxtWZ6PyiUN3fQFQl X-Google-Smtp-Source: APXvYqyJyrRU5fNAg0821RFT14r80sTNF1dtxTz1082Nu0dWnTxuzB7U/7zc8rW+1ejPlIfdS2CIfQ== X-Received: by 2002:a05:600c:206:: with SMTP id 6mr6449153wmi.15.1571836029978; Wed, 23 Oct 2019 06:07:09 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc08937.dynamic.kabel-deutschland.de. [188.192.137.55]) by smtp.gmail.com with ESMTPSA id c144sm5303125wmd.1.2019.10.23.06.07.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2019 06:07:09 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 23 Oct 2019 14:59:43 +0200 Message-Id: <20191023125944.10292-5-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191023125944.10292-1-andreas.rheinhardt@gmail.com> References: <20191023125944.10292-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 5/6] avformat/hdsenc: Add explicit deinit function 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" hdsenc already had an explicit function to free all allocations in case of an error, but it was not marked as deinit function, so that it was not called automatically when the AVFormatContext for muxing gets freed. Using an explicit deinit function also makes the code cleaner by allowing to return immediately without "goto fail". Signed-off-by: Andreas Rheinhardt --- libavformat/hdsenc.c | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/libavformat/hdsenc.c b/libavformat/hdsenc.c index 026530ac36..9c42baa7dc 100644 --- a/libavformat/hdsenc.c +++ b/libavformat/hdsenc.c @@ -318,21 +318,18 @@ static int hds_write_header(AVFormatContext *s) ff_const59 AVOutputFormat *oformat; if (mkdir(s->url, 0777) == -1 && errno != EEXIST) { - ret = AVERROR(errno); av_log(s, AV_LOG_ERROR , "Failed to create directory %s\n", s->url); - goto fail; + return AVERROR(errno); } oformat = av_guess_format("flv", NULL, NULL); if (!oformat) { - ret = AVERROR_MUXER_NOT_FOUND; - goto fail; + return AVERROR_MUXER_NOT_FOUND; } c->streams = av_mallocz_array(s->nb_streams, sizeof(*c->streams)); if (!c->streams) { - ret = AVERROR(ENOMEM); - goto fail; + return AVERROR(ENOMEM); } for (i = 0; i < s->nb_streams; i++) { @@ -342,8 +339,7 @@ static int hds_write_header(AVFormatContext *s) if (!st->codecpar->bit_rate) { av_log(s, AV_LOG_ERROR, "No bit rate set for stream %d\n", i); - ret = AVERROR(EINVAL); - goto fail; + return AVERROR(EINVAL); } if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { if (os->has_video) { @@ -359,8 +355,7 @@ static int hds_write_header(AVFormatContext *s) os->has_audio = 1; } else { av_log(s, AV_LOG_ERROR, "Unsupported stream type in stream %d\n", i); - ret = AVERROR(EINVAL); - goto fail; + return AVERROR(EINVAL); } os->bitrate += s->streams[i]->codecpar->bit_rate; @@ -368,8 +363,7 @@ static int hds_write_header(AVFormatContext *s) os->first_stream = i; ctx = avformat_alloc_context(); if (!ctx) { - ret = AVERROR(ENOMEM); - goto fail; + return AVERROR(ENOMEM); } os->ctx = ctx; ctx->oformat = oformat; @@ -380,8 +374,7 @@ static int hds_write_header(AVFormatContext *s) AVIO_FLAG_WRITE, os, NULL, hds_write, NULL); if (!ctx->pb) { - ret = AVERROR(ENOMEM); - goto fail; + return AVERROR(ENOMEM); } } else { ctx = os->ctx; @@ -389,8 +382,7 @@ static int hds_write_header(AVFormatContext *s) s->streams[i]->id = c->nb_streams; if (!(st = avformat_new_stream(ctx, NULL))) { - ret = AVERROR(ENOMEM); - goto fail; + return AVERROR(ENOMEM); } avcodec_parameters_copy(st->codecpar, s->streams[i]->codecpar); st->codecpar->codec_tag = 0; @@ -404,7 +396,7 @@ static int hds_write_header(AVFormatContext *s) OutputStream *os = &c->streams[i]; int j; if ((ret = avformat_write_header(os->ctx, NULL)) < 0) { - goto fail; + return ret; } os->ctx_inited = 1; avio_flush(os->ctx->pb); @@ -415,7 +407,7 @@ static int hds_write_header(AVFormatContext *s) "%s/stream%d_temp", s->url, i); ret = init_file(s, os, 0); if (ret < 0) - goto fail; + return ret; if (!os->has_video && c->min_frag_duration <= 0) { av_log(s, AV_LOG_WARNING, @@ -426,9 +418,6 @@ static int hds_write_header(AVFormatContext *s) } ret = write_manifest(s, 0); -fail: - if (ret) - hds_free(s); return ret; } @@ -558,7 +547,6 @@ static int hds_write_trailer(AVFormatContext *s) rmdir(s->url); } - hds_free(s); return 0; } @@ -589,5 +577,6 @@ AVOutputFormat ff_hds_muxer = { .write_header = hds_write_header, .write_packet = hds_write_packet, .write_trailer = hds_write_trailer, + .deinit = hds_free, .priv_class = &hds_class, };