aboutsummaryrefslogtreecommitdiff
path: root/lib/libc/rpc
diff options
context:
space:
mode:
authorEnji Cooper <ngie@FreeBSD.org>2016-05-22 02:24:38 +0000
committerEnji Cooper <ngie@FreeBSD.org>2016-05-22 02:24:38 +0000
commit99d498608a1cb0857017f5aca0f7d3f1d8f477eb (patch)
tree3f75bfe3c5a2ece5be752389ac1af16f249ba86b /lib/libc/rpc
parent3552a026264914089c58b5dbb44d63072ce72de3 (diff)
downloadsrc-99d498608a1cb0857017f5aca0f7d3f1d8f477eb.tar.gz
src-99d498608a1cb0857017f5aca0f7d3f1d8f477eb.zip
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
Notes
Notes: svn path=/head/; revision=300387
Diffstat (limited to 'lib/libc/rpc')
-rw-r--r--lib/libc/rpc/netnamer.c26
1 files changed, 15 insertions, 11 deletions
diff --git a/lib/libc/rpc/netnamer.c b/lib/libc/rpc/netnamer.c
index e7a297213b05..c29f271d6792 100644
--- a/lib/libc/rpc/netnamer.c
+++ b/lib/libc/rpc/netnamer.c
@@ -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);
}