From owner-svn-src-head@FreeBSD.ORG Wed Jan 16 18:41:22 2013 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id F38BF6C7; Wed, 16 Jan 2013 18:41:21 +0000 (UTC) (envelope-from delphij@delphij.net) Received: from anubis.delphij.net (anubis.delphij.net [IPv6:2001:470:1:117::25]) by mx1.freebsd.org (Postfix) with ESMTP id C74EF1E9; Wed, 16 Jan 2013 18:41:21 +0000 (UTC) Received: from epsilon.delphij.net (drawbridge.ixsystems.com [206.40.55.65]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by anubis.delphij.net (Postfix) with ESMTPSA id 6230D12B12; Wed, 16 Jan 2013 10:41:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=delphij.net; s=anubis; t=1358361681; bh=X5PTNL2A2h+rC9GwDeI3GgcqIIQSEae7sFDKqakWCCA=; h=Date:From:Reply-To:To:CC:Subject:References:In-Reply-To; b=vWA1oG4ghvX6EqylpdOxQ7SwuYne+ci12TC2JoKHnp8+QigjW7dbkpN4MjQltP/di SZNpiOjPNFHShg0NgcMyIr9XC9qJ/PjFvAXtyall3z5528ScGpMXafH8TIszrM2W4T tZkq2zFVCzId6shpbq8RI7TcwFaCQAnIs41H3Pxc= Message-ID: <50F6F450.50102@delphij.net> Date: Wed, 16 Jan 2013 10:41:20 -0800 From: Xin Li Organization: The FreeBSD Project MIME-Version: 1.0 To: Garrett Cooper Subject: Re: svn commit: r245494 - head/bin/pwait References: <201301160503.r0G53qie087155@svn.freebsd.org> <50F6ED68.50602@delphij.net> <0928E58E-F510-47CD-957F-8C321B1210CC@gmail.com> In-Reply-To: <0928E58E-F510-47CD-957F-8C321B1210CC@gmail.com> X-Enigmail-Version: 1.4.6 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: "src-committers@freebsd.org" , Eitan Adler , Xin LI , "svn-src-all@freebsd.org" , "svn-src-head@freebsd.org" , "d@delphij.net" X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: d@delphij.net List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Jan 2013 18:41:22 -0000 -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA512 On 01/16/13 10:17, Garrett Cooper wrote: > On Jan 16, 2013, at 10:11 AM, Xin Li wrote: > >> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA512 >> >> On 01/16/13 09:47, Eitan Adler wrote: >>> On 16 January 2013 01:49, Xin LI wrote: >>>> This doesn't seem right -- you should never release memory >>>> before exit, especially for memory allocated in main(), >>>> unless this "main" is intended for different purpose like a >>>> monolithic shell that wants to avoid exec(). Note that >>>> pwait(1) have multiple exit points I don't think it's >>>> practical. >>> >>> ... >>> >>> There have been multiple conversations about this: on hackers, >>> on the commit lists, and on the clang analyzer lists. >>> >>> I don't care much how the final code looks: with either free >>> or return but please make sure that scan-build finds no >>> warnings. >> >> Yes I did. Using exit(3) tells clang that this is the final exit >> and thus eliminates the warning. >> >> It sounds like a bug (or arguably a feature) that clang does not >> recognize return in main()s... > > I would consider it a bug, but it's better to use exit(3) anyhow as > it prevents bugs from occurring in other OSes (like windows when > you use atexit and posix-compliant signal handlers). Well, calling exit(3) actually do less on C++ (dtor's are not called in this case, if any local object is declared on stack, which is done when the code say 'return') but the difference is less on C. In style(9) there is no explicit mention of using exit(3) but the example do use exit() instead of return() for main(). By the way speaking for exit(3) preventing bugs on other OSes, do you have reference to these issue? It sounds weird as I would see these as serious leakage which are normally fixed very quickly and we shouldn't be the first people who seeing them... Cheers, - -- Xin LI https://www.delphij.net/ FreeBSD - The Power to Serve! Live free or die -----BEGIN PGP SIGNATURE----- iQEcBAEBCgAGBQJQ9vRQAAoJEG80Jeu8UPuz5KEH/RP2XYZvg2kB7vraWe08uIcs gcwYH4GVbxKbLWWjdSpBHLXVoPqOy7/n3UcKKt27vPzxo+VAiWZJUXPk9PZo0ePb WYqLEzjtfsYWbbIzdHzaB0pUQZ/QuzyFWICj7mkgJQwdTcejlsLAjZ4kqxfuj0wB kPPZ0zKPDT2CR7v/DgHkMMHshuuEw7xm1gij4y6ggVP/Hi4laJVmhJq1+h99Jrtu CrzUDRerXGwPg0qWP9xDylrHGOwAERgUWNgO6gJ1BP+LkAnltCcojFQZd3gs2epb HSS3ejrrR2IRM5jmBFW1L+SyKZHhDOvFtNHAoeAnAOp6Ay4R9U3hy+sVRtO6Oe8= =6JOJ -----END PGP SIGNATURE-----