From owner-svn-src-all@freebsd.org Fri Aug 28 14:05:14 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 480E59C471E; Fri, 28 Aug 2015 14:05:14 +0000 (UTC) (envelope-from cse.cem@gmail.com) Received: from mail-yk0-f170.google.com (mail-yk0-f170.google.com [209.85.160.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 0DF661A01; Fri, 28 Aug 2015 14:05:13 +0000 (UTC) (envelope-from cse.cem@gmail.com) Received: by ykdz80 with SMTP id z80so16003391ykd.0; Fri, 28 Aug 2015 07:05:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=mime-version:reply-to:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=zdqEueWNokcH6eXn2/X/5DhD0OTXXEZy3WnGZ+CwcEg=; b=NcVgFI6bdXMqz+xqTqGiqzRzPu7Ik8gNMsATrOsQ/7kIH1tcW0+SU886oaDCwLCA3H 6UBH5pCF/CA5h3T+5d6KLRb4r2QZ5DwyrXaN0/OyLhQoemZmK7c7yqXwk71ZgbuHkFvp IwmxnPLClVR1LhZSwnvfbjW5L2/CPf6N/yiYWGkdftzpKj8UZeIYNOnW8T2HjH21z/6z 41VsntTSGS1d9sjgxcym4sJxtjrQH3K6exezoLXK8Y6FHig/QoPD/S6VX62xsTLvWs3r xYpy8RibdkB4c7TM5Ihs7eNGOr4OMi5/gGYhLS93jgYRk8jtBG4/EKlrGA5AOIQnegW6 mVcQ== X-Received: by 10.129.95.87 with SMTP id t84mr9198812ywb.29.1440770706873; Fri, 28 Aug 2015 07:05:06 -0700 (PDT) Received: from mail-yk0-f175.google.com (mail-yk0-f175.google.com. [209.85.160.175]) by smtp.gmail.com with ESMTPSA id y129sm5322303ywc.6.2015.08.28.07.05.06 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 28 Aug 2015 07:05:06 -0700 (PDT) Received: by ykdz80 with SMTP id z80so16002999ykd.0; Fri, 28 Aug 2015 07:05:06 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.170.73.136 with SMTP id p130mr8853220ykp.108.1440770706356; Fri, 28 Aug 2015 07:05:06 -0700 (PDT) Reply-To: cem@FreeBSD.org Received: by 10.37.48.134 with HTTP; Fri, 28 Aug 2015 07:05:06 -0700 (PDT) In-Reply-To: <55E01D9A.2090805@delphij.net> References: <201508280044.t7S0ixfW038766@repo.freebsd.org> <20150828044312.GA88538@FreeBSD.org> <55E01D9A.2090805@delphij.net> Date: Fri, 28 Aug 2015 07:05:06 -0700 Message-ID: Subject: Re: svn commit: r287236 - head/bin/df From: Conrad Meyer To: Xin LI Cc: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Content-Type: text/plain; charset=UTF-8 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 14:05:14 -0000 On Fri, Aug 28, 2015 at 1:36 AM, Xin Li wrote: > > > 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(). >> >> 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 = 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. So, a better commit log may have been: "Use exit() instead of return in main() to work around a broken static analyzer" Any C static analyzer must understand main(). Best, Conrad