From owner-svn-src-all@freebsd.org Sun May 22 02:24:39 2016 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 9505EB43A30; Sun, 22 May 2016 02:24:39 +0000 (UTC) (envelope-from ngie@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 5BC301A3E; Sun, 22 May 2016 02:24:39 +0000 (UTC) (envelope-from ngie@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u4M2OcAG087001; Sun, 22 May 2016 02:24:38 GMT (envelope-from ngie@FreeBSD.org) Received: (from ngie@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u4M2Ocs2087000; Sun, 22 May 2016 02:24:38 GMT (envelope-from ngie@FreeBSD.org) Message-Id: <201605220224.u4M2Ocs2087000@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ngie set sender to ngie@FreeBSD.org using -f From: Garrett Cooper Date: Sun, 22 May 2016 02:24:38 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r300387 - head/lib/libc/rpc X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.22 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: Sun, 22 May 2016 02:24:39 -0000 Author: ngie Date: Sun May 22 02:24:38 2016 New Revision: 300387 URL: https://svnweb.freebsd.org/changeset/base/300387 Log: getnetid(..): consistently fclose fd at the end of the function This mutes a false positive with cppcheck, but also helps eliminate future potential issues with this variable MFC after: 2 weeks Sponsored by: EMC / Isilon Storage Division Modified: head/lib/libc/rpc/netnamer.c Modified: head/lib/libc/rpc/netnamer.c ============================================================================== --- head/lib/libc/rpc/netnamer.c Sun May 22 02:02:18 2016 (r300386) +++ head/lib/libc/rpc/netnamer.c Sun May 22 02:24:38 2016 (r300387) @@ -243,6 +243,9 @@ getnetid(char *key, char *ret) char *lookup; int len; #endif + int rv; + + rv = 0; fd = fopen(NETIDFILE, "r"); if (fd == NULL) { @@ -253,13 +256,11 @@ getnetid(char *key, char *ret) return (0); #endif } - for (;;) { - if (fd == NULL) - return (0); /* getnetidyp brings us here */ + while (fd != NULL) { res = fgets(buf, sizeof(buf), fd); if (res == NULL) { - fclose(fd); - return (0); + rv = 0; + goto done; } if (res[0] == '#') continue; @@ -282,9 +283,8 @@ getnetid(char *key, char *ret) lookup[len] = 0; strcpy(ret, lookup); free(lookup); - if (fd != NULL) - fclose(fd); - return (2); + rv = 2; + goto done; #else /* YP */ #ifdef DEBUG fprintf(stderr, @@ -310,10 +310,14 @@ getnetid(char *key, char *ret) } if (strcmp(mkey, key) == 0) { strcpy(ret, mval); - fclose(fd); - return (1); - + rv = 1; + goto done; } } } + +done: + if (fd != NULL) + fclose(fd); + return (rv); }