From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.ffmpeg.org (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id 634024C8AF for ; Wed, 6 Aug 2025 09:14:56 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id 7BB8468C6C8; Wed, 6 Aug 2025 12:14:53 +0300 (EEST) Received: from nef.ens.fr (nef2.ens.fr [129.199.96.40]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id 69C18687C56 for ; Wed, 6 Aug 2025 12:14:52 +0300 (EEST) X-ENS-nef-client: 129.199.129.80 ( name = phare.normalesup.org ) Received: from phare.normalesup.org (phare.normalesup.org [129.199.129.80]) by nef.ens.fr (8.14.4/1.01.28121999) with ESMTP id 5769EpM8031909 for ; Wed, 6 Aug 2025 11:14:51 +0200 Received: by phare.normalesup.org (Postfix, from userid 1001) id 729F02EFE3; Wed, 6 Aug 2025 11:14:51 +0200 (CEST) Date: Wed, 6 Aug 2025 11:14:51 +0200 From: Nicolas George To: FFmpeg development discussions and patches Message-ID: References: <20250805185609.11596-1-jiashengjiangcool@gmail.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.4.3 (nef.ens.fr [129.199.96.32]); Wed, 06 Aug 2025 11:14:51 +0200 (CEST) Subject: Re: [FFmpeg-devel] [PATCH] examples: Replace with proper error handling to avoid potential memory errors 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Alexander Strasser via ffmpeg-devel (HE12025-08-06): > I'm a bit undecided about this; especially because these are example files. > > Best would be to have them correct, small, and beautiful while still > promoting good C practices. Good C practices are verbose, and verbosity makes for poor examples. > I agree that the patch as proposed is not an improvement over all. > > I would say it would be best to shorten it to only the first change: > > --- a/doc/examples/decode_audio.c > +++ b/doc/examples/decode_audio.c > @@ -128,41 +128,48 @@ int main(int argc, char **argv) > outfilename = argv[2]; > > pkt = av_packet_alloc(); > + if (!pkt) > + exit(1); Yes, the first change is necessary, it is not just good practice. It would be better like the next ones, with an error message, though. This, IMHO, is the sweet spot between verbosity and API didactics: codec = avcodec_find_decoder(AV_CODEC_ID_MP2); if (!codec) { fprintf(stderr, "Codec not found\n"); exit(1); } If we really want to bring attention to good practices, we can add: exit(1); /* or proper cleanup and returning */ And in any case, the commit message should inaccurately pretend to fix possible leaks. Regards, -- Nicolas George _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".