Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 14 Apr 2014 21:11:39 +0300
From:      Konstantin Belousov <kostikbel@gmail.com>
To:        Christian Brueffer <brueffer@FreeBSD.org>
Cc:        svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org
Subject:   Re: svn commit: r264422 - head/sys/kern
Message-ID:  <20140414181139.GL4016@kib.kiev.ua>
In-Reply-To: <534B07EA.7080400@FreeBSD.org>
References:  <201404132123.s3DLNGvJ048359@svn.freebsd.org> <20140413214633.GF4016@kib.kiev.ua> <534B07EA.7080400@FreeBSD.org>

next in thread | previous in thread | raw e-mail | index | archive | help

--u3bvv0EcKsvvYeex
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Sun, Apr 13, 2014 at 11:55:54PM +0200, Christian Brueffer wrote:
> On 4/13/14 11:46 PM, Konstantin Belousov wrote:
> > On Sun, Apr 13, 2014 at 09:23:16PM +0000, Christian Brueffer wrote:
> >> Author: brueffer
> >> Date: Sun Apr 13 21:23:15 2014
> >> New Revision: 264422
> >> URL: http://svnweb.freebsd.org/changeset/base/264422
> >>
> >> Log:
> >>   Free buf after usage.
> >>  =20
> >>   CID:		1199377
> >>   Found with:	Coverity Prevent(tm)
> >>   MFC after:	1 week
> >>
> >> Modified:
> >>   head/sys/kern/imgact_elf.c
> >>
> >> Modified: head/sys/kern/imgact_elf.c
> >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D
> >> --- head/sys/kern/imgact_elf.c	Sun Apr 13 21:13:33 2014	(r264421)
> >> +++ head/sys/kern/imgact_elf.c	Sun Apr 13 21:23:15 2014	(r264422)
> >> @@ -1746,8 +1746,10 @@ __elfN(note_threadmd)(void *arg, struct=20
> >>  	size =3D 0;
> >>  	__elfN(dump_thread)(td, buf, &size);
> >>  	KASSERT(*sizep =3D=3D size, ("invalid size"));
> >> -	if (size !=3D 0 && sb !=3D NULL)
> >> +	if (size !=3D 0 && sb !=3D NULL) {
> >>  		sbuf_bcat(sb, buf, size);
> >> +		free(buf, M_TEMP);
> >> +	}
> >>  	*sizep =3D size;
> >>  }
> >> =20
> > Why conditioning free() on size !=3D 0 ?
> > IMO free(buf) must be done always, since buf is initialized for the case
> > when malloc() is not called.
> >=20
>=20
> The corresponding malloc() call is behind a similar conditional, so it
> seemed good to be symmetrical here (since buf if NULL otherwise anyway).
>=20
> I can change it to call free() unconditionally if you prefer, I don't
> mind either way.

Yes, I think that unconditional call would be better, due to strange
interface of dump_thread.  It could modify the size, but for now this
is effectively disallowed by KASSERT().

Also, while there, I would change the code
	buf =3D NULL;
	if (size !=3D 0 && sb !=3D NULL)
		buf =3D malloc(size, M_TEMP, M_ZERO | M_WAITOK);
to avoid useless initialization if buf, like this:
	if (size !=3D 0 && sb !=3D NULL)
		buf =3D malloc(size, M_TEMP, M_ZERO | M_WAITOK);
	else
		buf =3D NULL;


--u3bvv0EcKsvvYeex
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.22 (FreeBSD)

iQIcBAEBAgAGBQJTTCTbAAoJEJDCuSvBvK1B5bYQAJ/HwLayPx/qmBrKaP2M4+jK
W0Ziib27ZWUEgwl+GNXHQN8HtPM6uauHFx9eWh0Ymdajsh+3A/Zue2/vtz6XzUfL
HBfyB/WGXjRenR07kC6JkJS9fWJDUjF/N2RcwQxStOS71FIkhZQtCOeGYPp2OHmw
NG9e+cl48lwgegJaYCyCesl0nb4fxYRw6hzKTEy8MWzAqKd8BtKJwy71LQLroa3n
9f+EwSM2dL9tnL/WalJkiV5+fOH2hfkSLPx7hpkJakOvIKQ8eoAHnEQZkhmblP52
LzS9p5tF8cxQlcPaSykwQ1f5UF1ZJixkTmE27xdOIpjA0T54Zz+RAtq280DlfZSY
RMB4bAIjaPxRQ9St0Iz8cAyRBpvDSsRdNw9tgGe/yupCs65QGoWNEIibskY9tP/G
L3JPuv8mZEPkZP0UI6qRD0aGcSu/jm6/LoUlT7+rTIAqXtR3TRlcLNxbdJl9tWh+
Gax5+buW2t98P4ONIxCAITH9aBgR0B2iKKjikg3oZMi2bKyBK12zcEykwb05oSTi
kogl6RKtDJ212UzXCXx1kodvbXOOEdUGNB7azoD+tjSXaKsN4/4PC+FfW5EtDcSD
VgPvtXunDAxEnzrc7mZ4K9pb2EPHQkhKomSs4k435TOxZ2fi54sjFd4cT+z3SjYJ
/bzthR73n14xCysLFPlQ
=ft3Y
-----END PGP SIGNATURE-----

--u3bvv0EcKsvvYeex--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20140414181139.GL4016>