From patchwork Sat Aug 27 13:58:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 37512 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:139a:b0:8f:1db5:eae2 with SMTP id w26csp897790pzh; Sat, 27 Aug 2022 06:59:08 -0700 (PDT) X-Google-Smtp-Source: AA6agR4IokWRKViWCiR+rPQWf5hnX+o2oVi3eWaimogM3UjWrxmzuR6OxUCzMwG/9/tQT1fvvYqj X-Received: by 2002:a05:6402:90e:b0:443:ec4b:2b03 with SMTP id g14-20020a056402090e00b00443ec4b2b03mr10028621edz.71.1661608748320; Sat, 27 Aug 2022 06:59:08 -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 l18-20020a1709067d5200b0073d8ccd2bacsi2837230ejp.116.2022.08.27.06.59.08; Sat, 27 Aug 2022 06:59:08 -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=S4kQo6F5; 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 5526468BA42; Sat, 27 Aug 2022 16:59:05 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05olkn2035.outbound.protection.outlook.com [40.92.89.35]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DA50368B8CC for ; Sat, 27 Aug 2022 16:58:58 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Cd1b1nb3JtKOl2BroKmam8REhAV7DPYM8TpJj2WtczXQ55IGWmuMLrUdDMYQh2AYH7SDvN0TgsfAOLCbA4gfOqUV/7/3HJ79AcQFXO2PGaafEAY4QNaBLKlAgzqxDWkP+grCVYwNmlP2Aa2hRkTIBWpwbQGjqhNSGZkdsKySkb2v193Yg1J6KkL3GljmxdZk9DFHnzUGOJGZ72g39D32FqsmI0wF9VJOO3H9Xk1tG+9V7RCo8mIyqxVteg4NnM3JFOokWR0Sb8xJsCrs/UHIugo//9tHZLf8PZh1GOoefrbof4FfMMaO76LIsDdfmZQubT5QsnR6tNqEAX4e+9enOA== 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=rCjFWcPWTBFYnqDet+g5moAgHfQJd6LTgHcdRun53fI=; b=D154cDArZkf8IK30J4nIHO6z4w69b5buKTFcJUDakFNtYltRVm0m3YeVpn2Airphlz0lnSvkEv0711nOedmJPAugFrMuBQz/L94rGH7EuvcIjPSOfBrKO5IGI52G6z/4ENfb0rZpZA7oViLkli3MCZHQbaMUqlCp1JtVD/M3TQHVxqCsPPioGimEoDHFOc0h3gxmZ2JETpEbawwQZC218d00LSTDrIG5OyO0aOp9dERVrdbJt0BZLm5JvxRaA8y6bnPzifZsBQeXVNZG3vLKhbIND6a54ecEx4wE5cjk3CU3HmhrnQ9CaCm/yt+7vuoygZyit42VLF9cQfHpkoUz6Q== 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=rCjFWcPWTBFYnqDet+g5moAgHfQJd6LTgHcdRun53fI=; b=S4kQo6F53Ovnft8NG2hXuXCeS/2S/eXIv3B29H2Rq2DMrC2CvSVUNq7psOxO8pwLBhyrh57cefvF4i3qrYBxLOBI4/QIvcJdh68Ek1/32b+4c/iAN9uVCeNwG1g4ZDCM1v8sYlUd6QAM3Qjk87x1k4QJGM84mKTSFUXw3TjBSXh5V6SdsIxO6oUmcnWw18FYT/jOzQf8/nVHOj3UjVM2Fb4i6K8r/EvW9lqZG73PXbT26Yor5bXI/UnbZG83rODBGUEwiN/oLGXbAXGPi82K+p4qvR1oVEzi0MYmdw/xpC3MwzWpI0+S0xlDaxJwVMeNQ2G07b36jZg1Ac/tn+B8fA== Received: from DB6PR0101MB2214.eurprd01.prod.exchangelabs.com (2603:10a6:4:42::27) by GV1PR01MB8578.eurprd01.prod.exchangelabs.com (2603:10a6:150:2e::16) 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 13:58:56 +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 13:58:56 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 27 Aug 2022 15:58:46 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [xgGHdowCK8w009hTS5JDySY9kKxittlr] X-ClientProxiedBy: AS9PR06CA0218.eurprd06.prod.outlook.com (2603:10a6:20b:45e::7) To DB6PR0101MB2214.eurprd01.prod.exchangelabs.com (2603:10a6:4:42::27) X-Microsoft-Original-Message-ID: <20220827135847.3001236-1-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f11a084e-d440-460c-9e18-08da88344846 X-MS-Exchange-SLBlob-MailProps: feAVlmA1hHVjJ50BCCwDqmUfKVfAL0XJXnbMiq686EadOs/f8naYAzH4HLrvPXSur/OHdDWGI7yoUJOpQ02VWxId38zkuxUFaytMx7FK8/fobiLlMLLPPHCC9BZT3pB+fawXBJAManzGJGLfGOJgqXp2AGqpwdnSxSlUMc+jSsl1lUB2K1gGvTbC3aSrNk7TMor5k2xSHPUIpYmf2Sf7VUt25RbFrCG7WFIJYvDswRtZ6qe/MLcYV6FV/+eG+LLOObty9NeCfafhfSjq+Sjtdr2qhGrlY8WfQnP0c5+GqagDGJL4PROdkwsICVtKD21RTOhhAdMLr6r4lKWRJ4NrAKrd8N/C9nd9dpyeUQde0MMOs19ryiLvaMaLqNmdeBLK5Sp7fddXveTHd77jJO+RYOwYcXtRWzUImNj1gQR8fXHtqZzZMvxwZBGHozFfhj/pqdlv1IFfeRbulPqTYuy7I/pOCuWBJPyX2pt1IMx8KPGT4JENLEg6fVXkUaM6viIUul6mUBFhTj+5IgVk91tuVCd00UI6VbPAc+m3Sf0acnNAu3UC89SzIcVJDUq72iIOGtCYrzG3Rqw5yhCmoswNb7oieCs8az+CVnBM3CWlqQRmgMRU5jgD4yr9oh76L+dr/WPqeYNC1IgxZLHfADPDiRFvDxq/cUZ33mB+0tnnxMsvy59QYhvAoHcRXWw6YZKwtHwkLQ79efyT5zV3WuQUYA== X-MS-TrafficTypeDiagnostic: GV1PR01MB8578:EE_ X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: FaTd6QUvGUyE+E+iRY15QUdUx6ww44hxfeYvOgJFkn64Vl8/m6GimgOgiWRxzad+FZEUDLJx6W6S2eT7DCn4IwToW1x1ju7ZJ7ACJqcUn9e1Eu5nOHywdIL0m2RIw27ag6gRVy4BhgjV22oZ3MrfEFX2rAjg8l7pREYlKLxx4K/oYVnWpuhjruKVHUVo9ELUewrO/LH2CES+4pny3esLMB/i7A8Z4NUc4RSd28Ra4MH2W9lL6PBgLDd+2Qm/FrRhef+iTujLdod7FGxBaDnShz30fBHS7zIQw/IvC713owab5vtwHtTh8Eli9ltvnLp7C2h04zpb9hPUQvGn0R4MCs3N4QMP4LYxO2iPf2+rt2b2cMd4uqNh35yVTV2X1qJWovOYY8yl6enawJqRo/DAnhgSNQN+b4TUGvj4gsU90KFPXRN7bBt+O4hUacoguiG4oNLAFuURCYfD5a0D4bBOAo+9cYOxpVzDDfFUfUNv3xsroEHWcEpIPUtnAoqQAxDWZus7XeqD+NOwaPxu+68jr/h+cYgzhpz/1+wiEuDAPkfvV1RLoyp9hZpApqzHh7rDv51QNJ4FZlQLfgBJkdIfTa1pbki+HROMbMpT1z4jpSqOWr4RYT4RcwTIcHHbUfV4sqpxgyCf9nI3J1b50dvzJA== X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: yTVf1HzXpy75SRtnSpSCPg7jGvWz61dj/XXycdDpvhNMGma9JYBn8QJjH949DFV8dsVG54Ck2Xpefy8i1RYddcQ8mw+7gfSy6KT+I3EALac20gGhDuKgZ1rE0bbNFOGN7s3ppDzROecDWIxregI/Xhxz3s4oudj2CFskZMCNaDEzme84ZoxM5AH3+3w8oD48aIdTO2EpJ5wv+hx18MDPgpiTVyZvN+LQ4fZRN5Q2DxpQGVluTASonsbN7Y3c53ErBfJ4fLDttzBvmIBFHNpjDiHzuNGmfSlkBa2qv1kwZumiiWxQaQH0L9zkgjRlktr2WBGbrxTbqCqpvjIvNly18fW4NJB1o827JoONM+gNSdme5e3Pxv4jRjZ/bVxLDznkVxxYI2uEJsI8DU9iEMQm+L3JvcyVjoz2+HshFFboj6aexp6LPrExfoTLnTVbfj0zc9cS/qCNox4psobddo+Wdlyz/Ki6M++Wsrvm6IS2YCwSEGDS8OCickUe/BW1dDCBktBiN8oLdvFfPDBF5DCRqNAZPlM7QZWZu8vtL8V5SHRK99h8EfYpad6t05TuRanPkky4kS/B7ao+e5lG6mXZvxSh2uGzZUuArZhOa1VVOuRFd6X/rHQEnOORHij9/jnjxPM5f27C3BepdJ+s0Ka2zvY6QsLSrQykZGm/NYjOKY4UJpyhUaxKhJnMA/5/E0tO/Dik1G3FBMJu81qQ7J6JZbHp5VkdPdOVtNFi/JDgRPQjl5jMMxZ1PHwl+tSULq83A+ghtLMe2c4cyTDsvYLSHXorlgAE1dSPnPLz1awZDXvsYFGVltBQcosjNFitYvGcJoi0il8F65oLw8HfTWlshPS7tYIX2/p3dRzIdI3w2b1WpcaPhHPQPVBKKqC0pvkQY6+0862fLvUDjY+GBUNTXRgGi2pOr43UtmmI1DISrtuQCD44914pZxfX2bOhvur15k6bgSF8QwnoU5smTELI1NIf/euICPicjHJmc8oVSdsk2qVxjgkI/AHcvXP8BNRLEw5c2uWBmEzKWCZ1CQV/HMIA2cRUaiaEFG2Pg7bdquL1CFKB1nFhSnG3+1oT/oCD/rmvWY9Oal4r8fgiU1WQx6Ab6H38FCpYb0Wp5W9EsbLUCPJ4Bcu7/Z/0UVMut6ic8tKrK7XLkD8Ai5jFA1vaGRbZpq2R6mvHqpavHLIQMdMkt/rZknrgC++CXr76/eQiw3JiINq1ZA/LrvZu3XPZra6JAV6Mj41ZoroIsQ/0hQcTyHd1vvPu8F0/Jk2g06jtQBPTEgASj+nOUqiZy/mM7uyMp5tjrN1Lc4J8BOV2Ed4= X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: f11a084e-d440-460c-9e18-08da88344846 X-MS-Exchange-CrossTenant-AuthSource: DB6PR0101MB2214.eurprd01.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2022 13:58:56.2829 (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: GV1PR01MB8578 Subject: [FFmpeg-devel] [PATCH 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: 9LMEZSrvDiyg 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 b6f5c01ca3..47568dcebc 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_error_then_exit_program(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_error_then_exit_program(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_error_then_exit_program(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_error_then_exit_program(AVERROR(ENOMEM)); return new_elem; } diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index ef7177fc33..18b91e3ef6 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_error_then_exit_program(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_error_then_exit_program(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_error_then_exit_program(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_error_then_exit_program(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_error_then_exit_program(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_error_then_exit_program(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..26590000c7 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_error_then_exit_program(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_error_then_exit_program(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_error_then_exit_program(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_error_then_exit_program(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_error_then_exit_program(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..b0b8ecc868 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_error_then_exit_program(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_error_then_exit_program(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_error_then_exit_program(AVERROR(ENOMEM)); ist->pkt = av_packet_alloc(); if (!ist->pkt) - exit_program(1); + report_error_then_exit_program(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_error_then_exit_program(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_error_then_exit_program(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_error_then_exit_program(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_error_then_exit_program(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_error_then_exit_program(AVERROR(ENOMEM)); } ost->filtered_frame = av_frame_alloc(); if (!ost->filtered_frame) - exit_program(1); + report_error_then_exit_program(AVERROR(ENOMEM)); ost->pkt = av_packet_alloc(); if (!ost->pkt) - exit_program(1); + report_error_then_exit_program(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_error_then_exit_program(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_error_then_exit_program(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_error_then_exit_program(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_error_then_exit_program(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_error_then_exit_program(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_error_then_exit_program(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_error_then_exit_program(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_error_then_exit_program(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..7b15e9d3f7 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_error_then_exit_program(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..fe1e0f4f1b 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_error_then_exit_program(AVERROR(ENOMEM)); desc = NULL; while ((desc = avcodec_descriptor_next(desc))) codecs[i++] = desc;