]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/commit
MFC r287236:
authordelphij <delphij@ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f>
Mon, 14 Sep 2015 17:40:57 +0000 (17:40 +0000)
committerdelphij <delphij@ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f>
Mon, 14 Sep 2015 17:40:57 +0000 (17:40 +0000)
commitde18913943e1a61ee7a8c5f60100deffa0b7cebb
treefbf988d84516c70be399f3d1246cd50df921d839
parent2570017ab87b90607116cec652ba62d11198e76a
MFC r287236:

Use exit() instead of return in main().  The difference in practice
is subtle: C standard requires the language runtime to make return
of int from main() behave like calling exit(), and in FreeBSD we do:

exit(main(argc, argv, env))

In lib/csu/${ARCH}/crt1.c, so the real difference is using exit()
explicitly would use an additional stack frame.

Note however, if there is a on stack pointer is the last reference
of an allocated memory block, returning from the function would,
technically, result in a memory leak because we lost the last
reference to the memory block, and calling exit() from C runtime
could potentionally overwrite that stack frame that used to belong
to the main() function.

In practice, this is normally Okay because eventually the kernel
would tear down the whole address space that belongs to the process
in the _exit(2) system call, but the difference could confuse
compilers (which may want to do stack overflow checks) and static
analyzers.

Replacing return with exit() in main() allows compilers/static
analyzers to correctly omit or generate the right warnings when
they do not treat main() specifically.  With the current version
of clang on FreeBSD/amd64, use of exit() would result in slightly
smaller code being generated and eliminated a false positive
warning of memory leak.

git-svn-id: svn://svn.freebsd.org/base/stable/10@287790 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
bin/df/df.c