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 E35E74C420 for ; Sat, 12 Jul 2025 18:33:15 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id 05D4368ECC1; Sat, 12 Jul 2025 21:33:12 +0300 (EEST) Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id 2473768EC93 for ; Sat, 12 Jul 2025 21:33:05 +0300 (EEST) Received: by mail.gandi.net (Postfix) with ESMTPSA id 7CA36442F4 for ; Sat, 12 Jul 2025 18:33:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=niedermayer.cc; s=gm1; t=1752345184; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Mc4T4lfaVn9h0dfJUjtuS2TCVItvS5iApRbkqvNTcJ8=; b=PxEcUl0F0yBMsd26JsbQtIP2u6f52drTcnu1VMobEaUzo0OQZfgRaphWh/6/UaXjHCH0ub YGAtvqcA2y/ddVnsrgzv9veZDZlTgzjgfWu6ChpMZUo53tbYwTkjUKaUhmuDgK/VUkmU3F 4243tQb0aZZsp0Is3Piy4CMuiLpbTjuSxQxfp/ulIMOtfZ63LnoHz85aFXpUm99pPiZLqE XbBO0k9JF97KJrg+g7u9apiyzSxtXvpfounb396I55V7y5Vgw/5npxH9m+wLuVBBRx3Vmf htZBrQR5wlfLRB3+BhCpepuOI2haRw9p1dsrw/Fg3uy5hXBGBGMDfgQh2fBiEQ== Date: Sat, 12 Jul 2025 20:33:03 +0200 From: Michael Niedermayer To: FFmpeg development discussions and patches Message-ID: <20250712183303.GC29660@pb2> References: <20250710022047.1847641-1-502024330056@smail.nju.edu.cn> <20250710022047.1847641-2-502024330056@smail.nju.edu.cn> MIME-Version: 1.0 In-Reply-To: <20250710022047.1847641-2-502024330056@smail.nju.edu.cn> X-GND-State: clean X-GND-Score: -85 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgdegieelvdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfitefpfffkpdcuggftfghnshhusghstghrihgsvgenuceurghilhhouhhtmecufedtudenucesvcftvggtihhpihgvnhhtshculddquddttddmnegfrhhlucfvnfffucdludehmdenucfjughrpeffhffvuffkfhggtggujgesghdtreertddtvdenucfhrhhomhepofhitghhrggvlhcupfhivgguvghrmhgrhigvrhcuoehmihgthhgrvghlsehnihgvuggvrhhmrgihvghrrdgttgeqnecuggftrfgrthhtvghrnhepieegkedtjeduffejhfetgeejtdegteetgfegtdfhjefgvefhteegkeejtddvhfevnecukfhppeeguddrieeirdeihedrudejieenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeeguddrieeirdeihedrudejiedphhgvlhhopehlohgtrghlhhhoshhtpdhmrghilhhfrhhomhepmhhitghhrggvlhesnhhivgguvghrmhgrhigvrhdrtggtpdhnsggprhgtphhtthhopedupdhrtghpthhtohepfhhfmhhpvghgqdguvghvvghlsehffhhmphgvghdrohhrgh X-GND-Sasl: michael@niedermayer.cc Subject: Re: [FFmpeg-devel] [PATCH v2 1/3] avformat/sapenc: fix leak in sap_write_header() 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: multipart/mixed; boundary="===============5838148383295052205==" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: --===============5838148383295052205== Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="V2MgaywNmuEaB2gx" Content-Disposition: inline --V2MgaywNmuEaB2gx Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Jul 10, 2025 at 10:20:45AM +0800, Lidong Yan wrote: > In sap_write_header(), ff_format_set_url() assign new allocated new_url > to contexts[i]->url but forgot to free it later. Add for loop to free > contexts[i]->url before av_free(context). >=20 > To prevent from writing free-for-loop in every return point, replace > `return 0` with `ret =3D 0` so normal execution can fall through fail > code. >=20 > Signed-off-by: Lidong Yan <502024330056@smail.nju.edu.cn> > --- > libavformat/sapenc.c | 13 +++++++++---- > 1 file changed, 9 insertions(+), 4 deletions(-) >=20 > diff --git a/libavformat/sapenc.c b/libavformat/sapenc.c > index 87a834a8d8..0567a754e2 100644 > --- a/libavformat/sapenc.c > +++ b/libavformat/sapenc.c > @@ -233,7 +233,6 @@ static int sap_write_header(AVFormatContext *s) > ret =3D AVERROR_INVALIDDATA; > goto fail; > } > - av_freep(&contexts); > av_log(s, AV_LOG_VERBOSE, "SDP:\n%s\n", &sap->ann[pos]); > pos +=3D strlen(&sap->ann[pos]); > sap->ann_size =3D pos; > @@ -244,11 +243,17 @@ static int sap_write_header(AVFormatContext *s) > goto fail; > } > =20 > - return 0; > + ret =3D 0; > =20 > fail: > - av_free(contexts); > - sap_write_close(s); > + if (contexts) { > + for (i =3D 0; i < s->nb_streams; i++) > + if (contexts[i]) > + av_free(contexts[i]->url); > + av_free(contexts); > + } contexts is an array of AVFormatContext, this does not look right also freeing the url of the AVFormatContexts that have been stored in priv_data a few lines earlier looks wrong [...] --=20 Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Many that live deserve death. And some that die deserve life. Can you give it to them? Then do not be too eager to deal out death in judgement. For even the very wise cannot see all ends. -- Gandalf --V2MgaywNmuEaB2gx Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iF0EABEKAB0WIQSf8hKLFH72cwut8TNhHseHBAsPqwUCaHKqXAAKCRBhHseHBAsP qxIbAJ9AtBVFq0hLV3Xh+NtO5EinaeY4OQCfeW1xw3IhHuycvYn12wMNQ79JKj0= =7MzT -----END PGP SIGNATURE----- --V2MgaywNmuEaB2gx-- --===============5838148383295052205== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ 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". --===============5838148383295052205==--