svn commit: r300387 - head/lib/libc/rpc
Garrett Cooper
ngie at FreeBSD.org
Sun May 22 02:24:39 UTC 2016
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);
}
More information about the svn-src-all
mailing list