From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 564D94921A for ; Tue, 6 Feb 2024 00:40:13 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 39A3868D03F; Tue, 6 Feb 2024 02:40:11 +0200 (EET) Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9A9226800D8 for ; Tue, 6 Feb 2024 02:40:04 +0200 (EET) Received: by mail.gandi.net (Postfix) with ESMTPSA id B9DAC60002 for ; Tue, 6 Feb 2024 00:40:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=niedermayer.cc; s=gm1; t=1707180003; 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=qgbCh3yitUtZc+48ATBJclbLseJhhU6daxsbpG76qP8=; b=JLKSuGvLZ+2H/6wpB7Zvz6BlbfPf8uj3nAaU/YIBFwCqOFdguCWsmTRAdyOJhU2aMAzqYi 1WkekmiMXcjI5iEOfQnAlMO300tvLLqgjrO10Gl0/dWm2kZm64p5BIo0I8AK+o16csBJK+ Jm1ho7CuwPMLa+uFtJgitgXHBO8jgY6ljrMK2MmjqR97FdDEYHXY/mFOxZof/q3N4ASO/P zHVnhGCnrdmM8/KZaKKycnPbr3TQ7M4p3jwlRIRdPzt9/Ou5LunAudK5E5k8aSSWpKrh6s xe1egro6GfWC3f6aFbmRoQ12nHKwEPKwFxM8QCf5BvmPn8BMbzq0+W8AYZTlrA== Date: Tue, 6 Feb 2024 01:40:01 +0100 From: Michael Niedermayer To: FFmpeg development discussions and patches Message-ID: <20240206004001.GV6420@pb2> References: <20240205114459.8317-1-michael@niedermayer.cc> MIME-Version: 1.0 In-Reply-To: X-GND-Sasl: michael@niedermayer.cc Subject: Re: [FFmpeg-devel] [PATCH 1/2] avfilter/signature_lookup: dont leave uncleared pointers in sll_free() 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="===============0317664994174742599==" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: --===============0317664994174742599== Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="PbeD/+xqbjjTx4Xy" Content-Disposition: inline --PbeD/+xqbjjTx4Xy Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Feb 05, 2024 at 12:51:57PM +0100, Andreas Rheinhardt wrote: > Michael Niedermayer: > > Signed-off-by: Michael Niedermayer > > --- > > libavfilter/signature_lookup.c | 21 ++++++++++----------- > > 1 file changed, 10 insertions(+), 11 deletions(-) > >=20 > > diff --git a/libavfilter/signature_lookup.c b/libavfilter/signature_loo= kup.c > > index 86dd0c66754..52a97e1bc7e 100644 > > --- a/libavfilter/signature_lookup.c > > +++ b/libavfilter/signature_lookup.c > > @@ -37,6 +37,15 @@ > > #define STATUS_END_REACHED 1 > > #define STATUS_BEGIN_REACHED 2 > > =20 > > +static void sll_free(MatchingInfo **sll) > > +{ > > + while (*sll) { > > + MatchingInfo *tmp =3D *sll; > > + *sll =3D (*sll)->next; > > + av_free(tmp); > > + } >=20 > This does not clear the pointers at all. This does (and avoids > indirections). >=20 > static void sll_free(MatchingInfo **sllp) > { > MatchingInfo *sll =3D *sllp; >=20 > *sllp =3D NULL; > while (sll) { > MatchingInfo *tmp =3D sll; > sll =3D sll->next; > av_free(tmp); > } > } I tried it with code below, but your code is not different from mine in beh= avior just more complex output: (nil) 0x560e8daad2c0 (nil) vs. (nil) 0x557ae6e472c0 (nil) sll_free_n2() is simpler and will clear all, the reason i did not propose it, is its recursive and can hit stack space limits in principle sll_free_n3() and sll_free_n4() are other options that will clear all but maybe every choice contains bugs, i didnt really test them with more th= an one testcase ----------- #include #include #include #define FFSWAP(type,a,b) do{type SWAP_tmp=3D b; b=3D a; a=3D SWAP_tmp;}whil= e(0) static void av_free(void *ptr) { free(ptr); } static void av_freep(void *arg) { void *val; memcpy(&val, arg, sizeof(val)); memcpy(arg, &(void *){ NULL }, sizeof(val)); av_free(val); } typedef struct MatchingInfo { struct MatchingInfo *next; } MatchingInfo; static void sll_free_n(MatchingInfo **sll) { while (*sll) { MatchingInfo *tmp =3D *sll; *sll =3D (*sll)->next; av_free(tmp); } } static void sll_free_n2(MatchingInfo **sll) { if (*sll) sll_free_n(&(*sll)->next); av_freep(sll); } static void sll_free_n3(MatchingInfo **sll) { while (*sll) { MatchingInfo *tmp =3D *sll; *sll =3D tmp->next; tmp->next =3D NULL; av_free(tmp); } } static void sll_free_n4(MatchingInfo **sll) { MatchingInfo *tmp =3D NULL; while (*sll) { FFSWAP(MatchingInfo *, tmp, (*sll)->next); av_freep(sll); FFSWAP(MatchingInfo *, tmp, *sll); } } static void sll_free_r(MatchingInfo **sllp) { MatchingInfo *sll =3D *sllp; *sllp =3D NULL; while (sll) { MatchingInfo *tmp =3D sll; sll =3D sll->next; av_free(tmp); } } main() { MatchingInfo *mi, *m1, *m2; m1 =3D mi =3D malloc(sizeof(MatchingInfo)); m2 =3D mi->next =3D malloc(sizeof(MatchingInfo)); m2->next=3D NULL; sll_free_r(&mi); printf("%p %p %p\n", mi, m1->next, m2->next); } [...] --=20 Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB In fact, the RIAA has been known to suggest that students drop out of college or go to community college in order to be able to afford settlements. -- The RIAA --PbeD/+xqbjjTx4Xy Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iF0EABEIAB0WIQSf8hKLFH72cwut8TNhHseHBAsPqwUCZcF/2gAKCRBhHseHBAsP q7a9AKCUNBQ/UUA9WBdUr+CLJIQl4xPF+gCfcZUQXPno1/JwVdWx/kGyz22vaE8= =xHID -----END PGP SIGNATURE----- --PbeD/+xqbjjTx4Xy-- --===============0317664994174742599== 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". --===============0317664994174742599==--