From owner-svn-src-all@freebsd.org Fri Aug 28 08:36:48 2015 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id A80FB9C4916; Fri, 28 Aug 2015 08:36:48 +0000 (UTC) (envelope-from delphij@delphij.net) Received: from anubis.delphij.net (anubis.delphij.net [64.62.153.212]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "anubis.delphij.net", Issuer "StartCom Class 1 Primary Intermediate Server CA" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 87F2699C; Fri, 28 Aug 2015 08:36:48 +0000 (UTC) (envelope-from delphij@delphij.net) Received: from Xins-MBP.home.us.delphij.net (c-71-202-112-39.hsd1.ca.comcast.net [71.202.112.39]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by anubis.delphij.net (Postfix) with ESMTPSA id 72D6C1D336; Fri, 28 Aug 2015 01:36:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=delphij.net; s=anubis; t=1440751007; x=1440765407; bh=uwu4U7Xp3YBLPEGvR+A4vLk23j1bDIJTQ14Sqp3xHSE=; h=Subject:To:References:Cc:From:Date:In-Reply-To; b=0LjZMzrBWwb2LEcPplVReNpqDtksPmDy5k9Q/hTJ1edqJHsl+nMKxCYz/0CWlrq2k rMbrTt8YxHg3ygY0ydkPTk75XFlBmzXEklcpBOsJxhAz8EEN/nLgHBDMeLhECmTAD6 0vYbax51BFuhw6Mdlr3/lWac7xnED4L7959K0Bw8= Subject: Re: svn commit: r287236 - head/bin/df To: Alexey Dokuchaev , Xin LI References: <201508280044.t7S0ixfW038766@repo.freebsd.org> <20150828044312.GA88538@FreeBSD.org> Cc: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org From: Xin Li X-Enigmail-Draft-Status: N1110 Message-ID: <55E01D9A.2090805@delphij.net> Date: Fri, 28 Aug 2015 01:36:42 -0700 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 In-Reply-To: <20150828044312.GA88538@FreeBSD.org> Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="GR834R286OcfDwOPMBJXse9QHJBOp5Eop" X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 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: Fri, 28 Aug 2015 08:36:48 -0000 This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --GR834R286OcfDwOPMBJXse9QHJBOp5Eop Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable On 8/27/15 21:43, Alexey Dokuchaev wrote: > On Fri, Aug 28, 2015 at 12:44:59AM +0000, Xin LI wrote: >> New Revision: 287236 >> URL: https://svnweb.freebsd.org/changeset/base/287236 >> >> Log: >> Use exit() instead of return in main(). >=20 > Because?.. Because the explicit exit() have a subtle difference from returning from main(), and that could confuse static analyzers. I thought it was obvious and too much for trivial changes like this. Let me try again: C standard defines that when main() returns to the startup code, the latter is required by the standard to call exit() with main()'s return value, should main() be defined to return a type compatible with int. On FreeBSD, this is done by lib/csu/${ARCH}/crt1.c. Note, however, that return'ing from a C function means the stack contents, for example, variables defined in function scope, are discarded. Therefore, if, let's say one defined a pointer in the function scope, like: void *p; And then later assign a block of memory allocated from heap to it: p =3D malloc(size); Since p is in function scope, upon return, it's gone. If there is no other pointers that referenced the memory block referenced by p, the memory block is _technically_ leaked. This does not matter in practice because exit() or returning from main are both the points of termination, and the kernel would then reclaim all memory pages that belongs to the process. However, doing exit() makes it more explicit that this is the point of no returns, actually, it hints the compiler or a static analyzer to do the right thing without needing to make main() a special case. Cheers, --GR834R286OcfDwOPMBJXse9QHJBOp5Eop Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- iQIcBAEBCgAGBQJV4B2dAAoJEJW2GBstM+nsfo0P/jEEO5rpHeyocrC55L7gVDUk Zd/5IrjM1kX3Fj9xLTvUHiUvcdgw7QzWoQ3YD+F5toX9Z0kklQ6e+b7sHyXyj/vb IVy2XgBAPwj5rLh5X9/2cK9CgZiI5CuLQER1AyYfxx2S1MKg2yLcnhRtz13M95fw IoN0tPhCspJob8IlYcXfEwNx5ZwiwThLU4Nv2p/x18Tus9I4tY/mJM17X/yEp3ih 5otK6tB+qqCiiTPwACXhUwTuAqTIyoq8jKRX7Dw9ZpfBPHFgI/793Lo2s6RJKQRW U06sJUGDRwhf3XZ488/d1JzYu5zerk5p0AK6L0qyho6SamEPEOLyLJHc119GKRfU I4SeQKJ0RmML7+1XHzoRIoL66vAjmpk7SNZ3o2sSB/MzRAaNw17HBjAyRDtIFuXX PaHrj/xJBkjemjKY7CtzIUnFW8/V14EHSdDMgzpliUscgCGrx5UdLiWMBO4Bbb8q db8TCtxCZzfqngBCowoIlXkw9uRdMNvgHgX9zHvjuoNOxj8RLb7h5rT4HSsJL6JC f+8i+M89dBKUhNzgPcB+Dx8T6UxmjDRej6xMYFpZ1xdeKtsBoxriz0Qu86Cichf5 y2QFmfQ8URLUobMsANHXVNTP01Y/TAkDixzjuQBX4gbWW1Ffip4zhT+j7RicY5No piR8BgAwvTetamipVk6J =l7pV -----END PGP SIGNATURE----- --GR834R286OcfDwOPMBJXse9QHJBOp5Eop--