svn commit: r245494 - head/bin/pwait

Xin Li delphij at delphij.net
Wed Jan 16 18:41:22 UTC 2013


-----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 <delphij at delphij.net> wrote:
> 
>> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA512
>> 
>> On 01/16/13 09:47, Eitan Adler wrote:
>>> On 16 January 2013 01:49, Xin LI <delphij at gmail.com> 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 <delphij at delphij.net>    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-----


More information about the svn-src-all mailing list