From owner-svn-src-all@FreeBSD.ORG Mon Apr 14 18:11:50 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 2A37DCAA; Mon, 14 Apr 2014 18:11:50 +0000 (UTC) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id A316A188E; Mon, 14 Apr 2014 18:11:49 +0000 (UTC) Received: from tom.home (kostik@localhost [127.0.0.1]) by kib.kiev.ua (8.14.8/8.14.8) with ESMTP id s3EIBdtB054950; Mon, 14 Apr 2014 21:11:39 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.8.3 kib.kiev.ua s3EIBdtB054950 Received: (from kostik@localhost) by tom.home (8.14.8/8.14.8/Submit) id s3EIBdm1054949; Mon, 14 Apr 2014 21:11:39 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Mon, 14 Apr 2014 21:11:39 +0300 From: Konstantin Belousov To: Christian Brueffer Subject: Re: svn commit: r264422 - head/sys/kern Message-ID: <20140414181139.GL4016@kib.kiev.ua> References: <201404132123.s3DLNGvJ048359@svn.freebsd.org> <20140413214633.GF4016@kib.kiev.ua> <534B07EA.7080400@FreeBSD.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="u3bvv0EcKsvvYeex" Content-Disposition: inline In-Reply-To: <534B07EA.7080400@FreeBSD.org> User-Agent: Mutt/1.5.23 (2014-03-12) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on tom.home Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 14 Apr 2014 18:11:50 -0000 --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--