On a Monday in 2020, Ryan Gahagan wrote:
From: Barrett Schonefeld <bschoney(a)utexas.edu>
- src/util/virdnsmasq.c
Signed-off-by: Barrett Schonefeld <bschoney(a)utexas.edu>
---
src/util/virdnsmasq.c | 46 +++++++++++++------------------------------
1 file changed, 14 insertions(+), 32 deletions(-)
diff --git a/src/util/virdnsmasq.c b/src/util/virdnsmasq.c
index 5f477c976d..b41cdb8047 100644
--- a/src/util/virdnsmasq.c
+++ b/src/util/virdnsmasq.c
@@ -168,7 +168,6 @@ addnhostsWrite(const char *path,
FILE *f;
bool istmp = true;
size_t i, j;
- int rc = 0;
/* even if there are 0 hosts, create a 0 length file, to allow
* for runtime addition.
@@ -179,58 +178,51 @@ addnhostsWrite(const char *path,
if (!(f = fopen(tmp, "w"))) {
istmp = false;
if (!(f = fopen(path, "w"))) {
- rc = -errno;
- goto cleanup;
+ return -errno;
}
}
for (i = 0; i < nhosts; i++) {
if (fputs(hosts[i].ip, f) == EOF || fputc('\t', f) == EOF) {
- rc = -errno;
VIR_FORCE_FCLOSE(f);
While VIR_FORCE_FCLOSE saves errno so it should preserve its value
if (istmp)
unlink(tmp);
that's not true for unlink, so this kind of usage of 'rc' is necessary.
Jano