summaryrefslogtreecommitdiffstats
path: root/bin/df
diff options
context:
space:
mode:
authordelphij <delphij@FreeBSD.org>2015-09-14 17:40:57 +0000
committerdelphij <delphij@FreeBSD.org>2015-09-14 17:40:57 +0000
commitbdd5bccf11b6be95262b785e98db67c932e2e581 (patch)
treefbf988d84516c70be399f3d1246cd50df921d839 /bin/df
parentf1f74e3a0d58e4111a95270ae4d07a516f978489 (diff)
downloadFreeBSD-src-bdd5bccf11b6be95262b785e98db67c932e2e581.zip
FreeBSD-src-bdd5bccf11b6be95262b785e98db67c932e2e581.tar.gz
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.
Diffstat (limited to 'bin/df')
-rw-r--r--bin/df/df.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/bin/df/df.c b/bin/df/df.c
index 13ef129..ba87055 100644
--- a/bin/df/df.c
+++ b/bin/df/df.c
@@ -296,7 +296,7 @@ main(int argc, char *argv[])
prtstat(&mntbuf[i], &maxwidths);
if (cflag)
prtstat(&totalbuf, &maxwidths);
- return (rv);
+ exit(rv);
}
static char *
OpenPOWER on IntegriCloud