From patchwork Sat Aug 27 15:19:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 37515 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:139a:b0:8f:1db5:eae2 with SMTP id w26csp936800pzh; Sat, 27 Aug 2022 08:20:18 -0700 (PDT) X-Google-Smtp-Source: AA6agR43jKii+st8uM26G6PgKVtX1avpGBKayAdBqwp2YaYhyHnpOVYcm9pLemNTH7l9WPqxU5rf X-Received: by 2002:a17:907:c28:b0:73d:beb7:b9c2 with SMTP id ga40-20020a1709070c2800b0073dbeb7b9c2mr8378705ejc.336.1661613618291; Sat, 27 Aug 2022 08:20:18 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id r10-20020a508d8a000000b00446b4aa5d32si2586744edh.71.2022.08.27.08.20.17; Sat, 27 Aug 2022 08:20:18 -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=@outlook.com header.s=selector1 header.b="chyc/0ve"; arc=fail (body hash mismatch); 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=QUARANTINE dis=NONE) header.from=outlook.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9D31D68BA59; Sat, 27 Aug 2022 18:20:15 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05olkn2081.outbound.protection.outlook.com [40.92.91.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7AE0068B9E4 for ; Sat, 27 Aug 2022 18:20:08 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=T94RR+yWkkUgcfN4tT2eBvUsx0Am3NOcneqWhl00hS6Sd0H/g/Z26LaVlGs5k7QzgbRU3u0MzNbTM0C/Cm4hqNNx5Hn7CgyV4b1lFgxmsBk1kjpu8WRmkWbHe9ed/oYr9RzFquc7QITntX6NOlZJcjC0CDiZD8WxVHexNXdeSJtgtMrgr7L+Sa07jfhOofgMYQql+wG02FKN6l2FmAAcVk/frYVraxEJQKYp4EiA7mcIOx7aaGOS95bmuKjMOEB8gF0h2JWprJ0iQs2GUkRi/gpqgS7N44B4UyxgvM6sGlV9J8lkQVcuclleQq8DInc3fV/6xAiokccUTAtXG5ntsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=+f8zQf9O8Jxx0ai+5SoPRd+5adt5ow6mPRN6KwMozOY=; b=A66UhVX86kfte9Fp61B67795Bym9+1aADLWjM/JU4aVmQua1Q7FgwSGrGz3oDJmgVqOMupvS0AsymEC8/12jU4E5IX9VDQ/TAh/ar9I1HafUnfGR0S8kAmQ7xNJYiU/yvAH+rOV3fVi4GVMnDiJpBSUEdzqgB6v+e2clEefstKaMSjsXe7aAXGEoYxYHTs9L27qqHtD1WbrBV1Lu1LiPw+Cgrae28nfvdpvhNWzL1u2ATTOr+GNyBvYkgm76Hcjd9YDS28/0nulQUeNa4F6fRhGcz1bSFKdZcKMYlkzra2xGFXNACo0UwlY8n/065zxMbhbrcEIBQEDK+T0GEZ6SBA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=+f8zQf9O8Jxx0ai+5SoPRd+5adt5ow6mPRN6KwMozOY=; b=chyc/0vei3Xq+5rRn1HeuuIB1Ed1/Ac7MX4ssXKRma5LByD9Z4HtTuXu3XjEKbZ9pSCzmcFx1xRU6//2K0ziP6jQPdwU9aKJjqL1dK7xcL+qVj8o3Hqg1vQnquqHo5e9RIO+ID/Ebpz+AzJMM2K8GBxesvPsv9GnSVLh5NCb2+qBnsU/GnsNczyHst8xIKVyu9ZjecYgO4Iot23Eg/PPAePu7JQhs4V38YaelQNd8AJ+zBz54Lbg2dCxseHOmveXm4b7+DeCUJWWBd3atFEREcwFnXSfMVk3xgFaL7O4MEgTPgb6MYv53FetT+KWyNLkJqHwD93RdRUtk65KyM6k7g== Received: from DB6PR0101MB2214.eurprd01.prod.exchangelabs.com (2603:10a6:4:42::27) by HE1PR0101MB2154.eurprd01.prod.exchangelabs.com (2603:10a6:3:21::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5566.14; Sat, 27 Aug 2022 15:20:06 +0000 Received: from DB6PR0101MB2214.eurprd01.prod.exchangelabs.com ([fe80::4cb9:bf7a:dbc5:fe84]) by DB6PR0101MB2214.eurprd01.prod.exchangelabs.com ([fe80::4cb9:bf7a:dbc5:fe84%7]) with mapi id 15.20.5566.016; Sat, 27 Aug 2022 15:20:06 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 27 Aug 2022 17:19:57 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [yqi4QTvyaPAv0o6wWSyAJbyEF9K5Rk2E] X-ClientProxiedBy: AM5PR0701CA0020.eurprd07.prod.outlook.com (2603:10a6:203:51::30) To DB6PR0101MB2214.eurprd01.prod.exchangelabs.com (2603:10a6:4:42::27) X-Microsoft-Original-Message-ID: <20220827151958.3004351-1-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 55db2dab-4bbd-4973-2235-08da883f9f36 X-MS-Exchange-SLBlob-MailProps: feAVlmA1hHVjJ50BCCwDqmUfKVfAL0XJbvl2fBMnr39Rm/Fy1exCCzkdJR72VVrlLLkyOwp8hLfAeyBsVgslxkVDWxLEMjb3pmYGF2XCyS0FuK9jUx29UrCeHgs6MgjNUPPoJ8RxhtmCMTps03yRJ0Qrj/zelapBNrXBCNChgEYUZkqyYsZzTAejCuzzRjeWCdOF/4jyKIALMwOUsdvWonKJmDBCamYJWsuiNlNwvOwDAMygMtpIzEdNV2pU1TawJRg6XhaM1d7rZRYiDvwtrPjRLFkMp4cl46EFbyh7gRjJP4vCRKjxmlYssTIlP638+lQD+bG/twbkPyeaWZtWhkQdw3vhpJFOm3SCmvD2qyrWa+0KXsLxZ/FttpmlMc6oGTXjImavmWaHnq0t3799RjVS2WSwDkQTNT4ORBpmHdyvgy3Jmo/lrsmB2wBzko9o0SBpQiwlmmQQmWeYHRpM2VYOmBy7YCF3kxuUqetaJKmVpcirNqtPKag4YM6GCQfKdaDloguOWT8qXHhUP5RG0QxS2KaU+NVgo9kvVDR4+0yBZlTreAhVbH1wCasZMAC69ygzKAshwaMFWn0aEw//CidRKg6V0ip61QSHVIHBUPFWZ6RTgbE4c6V55UhrygLKD8rS7ZUPemY8tcp+RPrP7wn+HIQBDkR9/X+8dcfGXNDldhT3Rny5UcuXGDaM0s+G/y5r9vXf0s53RLau8Rjzeg== X-MS-TrafficTypeDiagnostic: HE1PR0101MB2154:EE_ X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: xR2VT2uVfFg+OEqqOhf74tbfiKA+yYjdfMPzns7pvzAYCPXQGL+pIiBlV+KLJ6DDn18lLcPB7kUG+KSgysjVmsTlxmJ+G7L6z7z5Z2KfY0pyFnJZcmm97mkfXzZNVTPTks1xmajODlfxn41xKbjjQX8DCa6IAxsPTj2qwjvYaS0Q1nvVJ9s3Aq5jDyLxYkjxpMkwPRG69qYBZYVJlyUBdjbcd8AeFFLnW6IuH2hlS6VJxWpKQidSJzoN0dlRaAFvVgE5XDi/gy+CwUO5WihlS+fPDf8T0shQ4psaJqSPzUc1ow4lXY4UW2qorbN2TL3MOP9IEENMyUAMl8Bo8xa1k5nL6GmnO3znQ/tvOy999t958V2plXWEJg6ytycYfIQIbR+U0QvYXD+SaTEdgnXM4Kifs5oiopLndvbM0w5sP0womRQ46Q6guVgVtVZEpAVfxb0hX7IBIlB7A0MEu/pXVBbl/CEJPSuEig4lkZyflyNqrYBE0msAsesv2V9SlwdCldqi8z3oKBFE2/aplKff6MmX1pEO8US+vGf2mlMq6sILMbus3humnS5GMAkGP4ii0EFm7vxuiu/hzgsoK+nDM4sEVyXcw6SaUkMwaaYOuey0Y7SQ/1bl0I1ZLsx1gzZ9X4cE4BuZSNx5CYdP4m+fYw== X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: FOrfzf8VFVB4+RIZhUu2xeNSEWivYxsrNi2SBK3d2hAHGAR4H/n1UjMPOb2CQEvuARZirJXaYoqismXsI9R9P0AoigaaZ5P65sOPT73ezwvMyWlIFpaRtC2QtWj0KMk64+9PhTYfwp3W5Kn55aCmxWQqgjThtsRfuO1E+KdIvYJ9ypdn2gCAubA78OWca5JNSkEgdJhH1U3xuHGjxXqTtDw4x+QCLEAWmB78mY/PBuNpADOguRcaG+O1XZd1zue8iIAnH51eqcuK3qBUQkhYv39ctUafJ3OEDdcZbF28gkRn/v6iuKRKD103NvzOp8ngLvy3QIFhPBGQ8Q0TgYRTvRL4bujI/o+hbEUflzdbUs5szV1+OXrlWqXfCVITU61+p8awly2mBg9WQPtWJW0XwGcF0Gg2YUh5FOZ6awZCzCT71n5VHBKC1MRTpEdpx/KQ+BPrLRtvgsJYpuJbGD94j2eZjTVEk3LrI1OT8XU6ciu254YE0vvILsoEfgL6XSfwWz68FQ6tqK/EPf00y+/jSUxDyOqmMJ+2T4mbv54WC4CqOpRZSPz9XQKTQDNqa/gi2MOC/eriq+gI+IXawMyhRuJtyGNYUHsGmWF1JPhzj2Z1cTXtDyURqtuW0U8nuozqUDTXs/UE5vyozm6re0XlPEGh+mggmDD4IpRlKWJOeJx2Kds6KzEirUvsFG9CBVhbYX2izpZ6oRCPT1udy6a2vfOv6w/fvzp6prBP9/aW2ZMvNsJmiMSDMKiD2y9izxB3caj6v5FzHqY9z3pyx36eC9unGO8aDCoAujWCCiq2E7AlkeTDDwYyS3BSLooV9bXOiY+p3hCQvndVjaq06g5Zk41PJv5oBFKPqemqBlV67roRRhAbFpftxodbKx8nt2DpobADprUeEnWeF+z4D5Z2QjNz6w3S6pg59msHDOJzpXaAeUGUk6E7cQTnH1JL5MKhgHUyLM1uXmH9Yt7zv1ke8PMSXxdotO7ZYrM/tqYKqR4Dlugkuw2CDNTat+Mtn2RSUzKjNfkQ8shASyvTvMiq4gOJH8jBLT9DTGeCipEQJYfhijb2sW/IQE9kWa0VUNdMkurB97YIQjNK6vh3q80wWFk9vsoYbjLv5vd90CPpA6DJ3LwjbX01/Ha8o6SJNacCwwXQqfbAsjNmrcnFpxOls1sNWTvJ18QMvuklmfsphb9pAf0QYGUJ0ok+UPGT7fcFoAD6zXD9f4kI1ozfuvf3f2S5h1bvWwhZDVCH6KzPer8egYJ6w9p5ovxGGM9y6YYvnPVjm/qNv9jbHJVGLPmgPhjJoz8LTEg0khFJK/iU3io= X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 55db2dab-4bbd-4973-2235-08da883f9f36 X-MS-Exchange-CrossTenant-AuthSource: DB6PR0101MB2214.eurprd01.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2022 15:20:06.4757 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0101MB2154 Subject: [FFmpeg-devel] [PATCH v2 2/3] fftools: Use report_error_then_exit_program() for allocation failures X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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" X-TUID: mGLVoTLfEw71 Signed-off-by: Andreas Rheinhardt --- fftools/cmdutils.c | 21 +++++-------- fftools/ffmpeg.c | 25 ++++++--------- fftools/ffmpeg_filter.c | 10 +++--- fftools/ffmpeg_opt.c | 70 ++++++++++++++++------------------------- fftools/ffprobe.c | 6 ++-- fftools/opt_common.c | 6 ++-- 6 files changed, 52 insertions(+), 86 deletions(-) diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c index da3d391694..f911c52be2 100644 --- a/fftools/cmdutils.c +++ b/fftools/cmdutils.c @@ -656,7 +656,7 @@ static void init_parse_context(OptionParseContext *octx, octx->nb_groups = nb_groups; octx->groups = av_calloc(octx->nb_groups, sizeof(*octx->groups)); if (!octx->groups) - exit_program(1); + report_and_exit(AVERROR(ENOMEM)); for (i = 0; i < octx->nb_groups; i++) octx->groups[i].group_def = &groups[i]; @@ -964,11 +964,8 @@ AVDictionary **setup_find_stream_info_opts(AVFormatContext *s, if (!s->nb_streams) return NULL; opts = av_calloc(s->nb_streams, sizeof(*opts)); - if (!opts) { - av_log(NULL, AV_LOG_ERROR, - "Could not alloc memory for stream options.\n"); - exit_program(1); - } + if (!opts) + report_and_exit(AVERROR(ENOMEM)); for (i = 0; i < s->nb_streams; i++) opts[i] = filter_codec_opts(codec_opts, s->streams[i]->codecpar->codec_id, s, s->streams[i], NULL); @@ -983,10 +980,8 @@ void *grow_array(void *array, int elem_size, int *size, int new_size) } if (*size < new_size) { uint8_t *tmp = av_realloc_array(array, new_size, elem_size); - if (!tmp) { - av_log(NULL, AV_LOG_ERROR, "Could not alloc buffer.\n"); - exit_program(1); - } + if (!tmp) + report_and_exit(AVERROR(ENOMEM)); memset(tmp + *size*elem_size, 0, (new_size-*size) * elem_size); *size = new_size; return tmp; @@ -999,10 +994,8 @@ void *allocate_array_elem(void *ptr, size_t elem_size, int *nb_elems) void *new_elem; if (!(new_elem = av_mallocz(elem_size)) || - av_dynarray_add_nofree(ptr, nb_elems, new_elem) < 0) { - av_log(NULL, AV_LOG_ERROR, "Could not alloc buffer.\n"); - exit_program(1); - } + av_dynarray_add_nofree(ptr, nb_elems, new_elem) < 0) + report_and_exit(AVERROR(ENOMEM)); return new_elem; } diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index ef7177fc33..8f53f5c7ef 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1094,10 +1094,8 @@ static void do_subtitle_out(OutputFile *of, return; ret = av_new_packet(pkt, subtitle_out_max_size); - if (ret < 0) { - av_log(NULL, AV_LOG_FATAL, "Failed to allocate subtitle encode buffer\n"); - exit_program(1); - } + if (ret < 0) + report_and_exit(AVERROR(ENOMEM)); sub->pts = pts; // start_display_time is required to be 0 @@ -2345,7 +2343,7 @@ static int transcode_subtitles(InputStream *ist, AVPacket *pkt, int *got_output, if (!ist->sub2video.sub_queue) ist->sub2video.sub_queue = av_fifo_alloc2(8, sizeof(AVSubtitle), AV_FIFO_FLAG_AUTO_GROW); if (!ist->sub2video.sub_queue) - exit_program(1); + report_and_exit(AVERROR(ENOMEM)); ret = av_fifo_write(ist->sub2video.sub_queue, &subtitle, 1); if (ret < 0) @@ -2874,7 +2872,7 @@ static void set_encoder_id(OutputFile *of, OutputStream *ost) encoder_string_len = sizeof(LIBAVCODEC_IDENT) + strlen(ost->enc->name) + 2; encoder_string = av_mallocz(encoder_string_len); if (!encoder_string) - exit_program(1); + report_and_exit(AVERROR(ENOMEM)); if (!of->bitexact && !ost->bitexact) av_strlcpy(encoder_string, LIBAVCODEC_IDENT " ", encoder_string_len); @@ -2897,10 +2895,8 @@ static void parse_forced_key_frames(char *kf, OutputStream *ost, n++; size = n; pts = av_malloc_array(size, sizeof(*pts)); - if (!pts) { - av_log(NULL, AV_LOG_FATAL, "Could not allocate forced key frames array.\n"); - exit_program(1); - } + if (!pts) + report_and_exit(AVERROR(ENOMEM)); p = kf; for (i = 0; i < n; i++) { @@ -2919,11 +2915,8 @@ static void parse_forced_key_frames(char *kf, OutputStream *ost, if (nb_ch > INT_MAX - size || !(pts = av_realloc_f(pts, size += nb_ch - 1, - sizeof(*pts)))) { - av_log(NULL, AV_LOG_FATAL, - "Could not allocate forced key frames array.\n"); - exit_program(1); - } + sizeof(*pts)))) + report_and_exit(AVERROR(ENOMEM)); t = p[8] ? parse_time_or_die("force_key_frames", p + 8, 1) : 0; t = av_rescale_q(t, AV_TIME_BASE_Q, avctx->time_base); @@ -3861,7 +3854,7 @@ static int process_input(int file_index) dst_data = av_packet_new_side_data(pkt, src_sd->type, src_sd->size); if (!dst_data) - exit_program(1); + report_and_exit(AVERROR(ENOMEM)); memcpy(dst_data, src_sd->data, src_sd->size); } diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 16622e49c1..8b32a80ebf 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -118,7 +118,7 @@ static const char *choose_pix_fmts(OutputFilter *ofilter, AVBPrint *bprint) av_bprintf(bprint, "%s%c", name, p[1] == AV_PIX_FMT_NONE ? '\0' : '|'); } if (!av_bprint_is_complete(bprint)) - exit_program(1); + report_and_exit(AVERROR(ENOMEM)); return bprint->str; } else return NULL; @@ -182,7 +182,7 @@ int init_simple_filtergraph(InputStream *ist, OutputStream *ost) InputFilter *ifilter; if (!fg) - exit_program(1); + report_and_exit(AVERROR(ENOMEM)); fg->index = nb_filtergraphs; ofilter = ALLOC_ARRAY_ELEM(fg->outputs, fg->nb_outputs); @@ -199,7 +199,7 @@ int init_simple_filtergraph(InputStream *ist, OutputStream *ost) ifilter->frame_queue = av_fifo_alloc2(8, sizeof(AVFrame*), AV_FIFO_FLAG_AUTO_GROW); if (!ifilter->frame_queue) - exit_program(1); + report_and_exit(AVERROR(ENOMEM)); GROW_ARRAY(ist->filters, ist->nb_filters); ist->filters[ist->nb_filters - 1] = ifilter; @@ -223,7 +223,7 @@ static char *describe_filter_link(FilterGraph *fg, AVFilterInOut *inout, int in) res = av_asprintf("%s:%s", ctx->filter->name, avfilter_pad_get_name(pads, inout->pad_idx)); if (!res) - exit_program(1); + report_and_exit(AVERROR(ENOMEM)); return res; } @@ -308,7 +308,7 @@ static void init_input_filter(FilterGraph *fg, AVFilterInOut *in) ifilter->frame_queue = av_fifo_alloc2(8, sizeof(AVFrame*), AV_FIFO_FLAG_AUTO_GROW); if (!ifilter->frame_queue) - exit_program(1); + report_and_exit(AVERROR(ENOMEM)); GROW_ARRAY(ist->filters, ist->nb_filters); ist->filters[ist->nb_filters - 1] = ifilter; diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 8128dcf9fb..ccb79d920c 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -996,7 +996,7 @@ static void add_input_streams(OptionsContext *o, AVFormatContext *ic) if (hwaccel_device) { ist->hwaccel_device = av_strdup(hwaccel_device); if (!ist->hwaccel_device) - exit_program(1); + report_and_exit(AVERROR(ENOMEM)); } ist->hwaccel_pix_fmt = AV_PIX_FMT_NONE; @@ -1027,10 +1027,8 @@ static void add_input_streams(OptionsContext *o, AVFormatContext *ic) ist->prev_pkt_pts = AV_NOPTS_VALUE; ist->dec_ctx = avcodec_alloc_context3(ist->dec); - if (!ist->dec_ctx) { - av_log(NULL, AV_LOG_ERROR, "Error allocating the decoder context.\n"); - exit_program(1); - } + if (!ist->dec_ctx) + report_and_exit(AVERROR(ENOMEM)); ret = avcodec_parameters_to_context(ist->dec_ctx, par); if (ret < 0) { @@ -1040,11 +1038,11 @@ static void add_input_streams(OptionsContext *o, AVFormatContext *ic) ist->decoded_frame = av_frame_alloc(); if (!ist->decoded_frame) - exit_program(1); + report_and_exit(AVERROR(ENOMEM)); ist->pkt = av_packet_alloc(); if (!ist->pkt) - exit_program(1); + report_and_exit(AVERROR(ENOMEM)); if (o->bitexact) ist->dec_ctx->flags |= AV_CODEC_FLAG_BITEXACT; @@ -1094,7 +1092,7 @@ static void add_input_streams(OptionsContext *o, AVFormatContext *ic) ist->par = avcodec_parameters_alloc(); if (!ist->par) - exit_program(1); + report_and_exit(AVERROR(ENOMEM)); ret = avcodec_parameters_from_context(ist->par, ist->dec_ctx); if (ret < 0) { @@ -1224,10 +1222,8 @@ static int open_input_file(OptionsContext *o, const char *filename) /* get default parameters from command line */ ic = avformat_alloc_context(); - if (!ic) { - print_error(filename, AVERROR(ENOMEM)); - exit_program(1); - } + if (!ic) + report_and_exit(AVERROR(ENOMEM)); if (o->nb_audio_sample_rate) { av_dict_set_int(&o->g->format_opts, "sample_rate", o->audio_sample_rate[o->nb_audio_sample_rate - 1].u.i, 0); } @@ -1476,10 +1472,8 @@ static char *get_line(AVIOContext *s, AVBPrint *bprint) while ((c = avio_r8(s)) && c != '\n') av_bprint_chars(bprint, c, 1); - if (!av_bprint_is_complete(bprint)) { - av_log(NULL, AV_LOG_FATAL, "Could not alloc buffer for reading preset.\n"); - exit_program(1); - } + if (!av_bprint_is_complete(bprint)) + report_and_exit(AVERROR(ENOMEM)); return bprint->str; } @@ -1567,10 +1561,8 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e double qscale = -1; int i; - if (!st) { - av_log(NULL, AV_LOG_FATAL, "Could not alloc stream.\n"); - exit_program(1); - } + if (!st) + report_and_exit(AVERROR(ENOMEM)); if (oc->nb_streams - 1 < o->nb_streamid_map) st->id = o->streamid_map[oc->nb_streams - 1]; @@ -1592,19 +1584,17 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e if (ost->enc) { ost->enc_ctx = avcodec_alloc_context3(ost->enc); - if (!ost->enc_ctx) { - av_log(NULL, AV_LOG_ERROR, "Error allocating the encoding context.\n"); - exit_program(1); - } + if (!ost->enc_ctx) + report_and_exit(AVERROR(ENOMEM)); } ost->filtered_frame = av_frame_alloc(); if (!ost->filtered_frame) - exit_program(1); + report_and_exit(AVERROR(ENOMEM)); ost->pkt = av_packet_alloc(); if (!ost->pkt) - exit_program(1); + report_and_exit(AVERROR(ENOMEM)); if (ost->enc) { AVIOContext *s = NULL; @@ -1897,28 +1887,22 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc, in MATCH_PER_STREAM_OPT(intra_matrices, str, intra_matrix, oc, st); if (intra_matrix) { - if (!(video_enc->intra_matrix = av_mallocz(sizeof(*video_enc->intra_matrix) * 64))) { - av_log(NULL, AV_LOG_FATAL, "Could not allocate memory for intra matrix.\n"); - exit_program(1); - } + if (!(video_enc->intra_matrix = av_mallocz(sizeof(*video_enc->intra_matrix) * 64))) + report_and_exit(AVERROR(ENOMEM)); parse_matrix_coeffs(video_enc->intra_matrix, intra_matrix); } MATCH_PER_STREAM_OPT(chroma_intra_matrices, str, chroma_intra_matrix, oc, st); if (chroma_intra_matrix) { uint16_t *p = av_mallocz(sizeof(*video_enc->chroma_intra_matrix) * 64); - if (!p) { - av_log(NULL, AV_LOG_FATAL, "Could not allocate memory for intra matrix.\n"); - exit_program(1); - } + if (!p) + report_and_exit(AVERROR(ENOMEM)); video_enc->chroma_intra_matrix = p; parse_matrix_coeffs(p, chroma_intra_matrix); } MATCH_PER_STREAM_OPT(inter_matrices, str, inter_matrix, oc, st); if (inter_matrix) { - if (!(video_enc->inter_matrix = av_mallocz(sizeof(*video_enc->inter_matrix) * 64))) { - av_log(NULL, AV_LOG_FATAL, "Could not allocate memory for inter matrix.\n"); - exit_program(1); - } + if (!(video_enc->inter_matrix = av_mallocz(sizeof(*video_enc->inter_matrix) * 64))) + report_and_exit(AVERROR(ENOMEM)); parse_matrix_coeffs(video_enc->inter_matrix, inter_matrix); } @@ -1975,7 +1959,7 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc, in MATCH_PER_STREAM_OPT(passlogfiles, str, ost->logfile_prefix, oc, st); if (ost->logfile_prefix && !(ost->logfile_prefix = av_strdup(ost->logfile_prefix))) - exit_program(1); + report_and_exit(AVERROR(ENOMEM)); if (do_pass) { char logfilename[1024]; @@ -2055,7 +2039,7 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc, in ost->last_frame = av_frame_alloc(); if (!ost->last_frame) - exit_program(1); + report_and_exit(AVERROR(ENOMEM)); } else check_streamcopy_filters(o, oc, ost, AVMEDIA_TYPE_VIDEO); @@ -2146,7 +2130,7 @@ static OutputStream *new_audio_stream(OptionsContext *o, AVFormatContext *oc, in ost->audio_channels_mapped + 1, sizeof(*ost->audio_channels_map) ) < 0 ) - exit_program(1); + report_and_exit(AVERROR(ENOMEM)); ost->audio_channels_map[ost->audio_channels_mapped++] = map->channel_idx; } @@ -2875,7 +2859,7 @@ static void set_channel_layout(OutputFilter *f, OutputStream *ost) /* Pass the layout through for all orders but UNSPEC */ err = av_channel_layout_copy(&f->ch_layout, &ost->enc_ctx->ch_layout); if (err < 0) - exit_program(1); + report_and_exit(AVERROR(ENOMEM)); return; } @@ -2896,7 +2880,7 @@ static void set_channel_layout(OutputFilter *f, OutputStream *ost) /* Use it if one is found */ err = av_channel_layout_copy(&f->ch_layout, &ost->enc->ch_layouts[i]); if (err < 0) - exit_program(1); + report_and_exit(AVERROR(ENOMEM)); return; } /* If no layout for the amount of channels requested was found, use the default diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c index 8983dc28cc..3344a06409 100644 --- a/fftools/ffprobe.c +++ b/fftools/ffprobe.c @@ -3291,10 +3291,8 @@ static int open_input_file(InputFile *ifile, const char *filename, int scan_all_pmts_set = 0; fmt_ctx = avformat_alloc_context(); - if (!fmt_ctx) { - print_error(filename, AVERROR(ENOMEM)); - exit_program(1); - } + if (!fmt_ctx) + report_and_exit(AVERROR(ENOMEM)); if (!av_dict_get(format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE)) { av_dict_set(&format_opts, "scan_all_pmts", "1", AV_DICT_DONT_OVERWRITE); diff --git a/fftools/opt_common.c b/fftools/opt_common.c index ae5e28a5af..7cd8b1c66e 100644 --- a/fftools/opt_common.c +++ b/fftools/opt_common.c @@ -639,10 +639,8 @@ static unsigned get_codecs_sorted(const AVCodecDescriptor ***rcodecs) while ((desc = avcodec_descriptor_next(desc))) nb_codecs++; - if (!(codecs = av_calloc(nb_codecs, sizeof(*codecs)))) { - av_log(NULL, AV_LOG_ERROR, "Out of memory\n"); - exit_program(1); - } + if (!(codecs = av_calloc(nb_codecs, sizeof(*codecs)))) + report_and_exit(AVERROR(ENOMEM)); desc = NULL; while ((desc = avcodec_descriptor_next(desc))) codecs[i++] = desc;