"Can't fdopen the snapshot config file %s: %s\n",
conf_name, strerror(errno));
rc = -1;
- goto out;
+ goto out_fd;
}
while (snapshot_fgets(fp, buf, MAX_BUF_SIZE) != NULL) {
out:
if (fd >= 0) {
- if (rc < 0) {
+ if (rc < 0)
flock(fd, LOCK_UN);
- close(fd);
- } else {
+ else
si->si_conf_fd = fd;
- }
}
-
+ /* fclose() closes any associated underlying file descriptor.
+ * explicit close(fd) not required
+ */
+ fclose(fp);
+ return rc;
+out_fd:
+ close(fd);
return rc;
}
rc = scnprintf(cmd + len, size - len - 1,
"-o %s=\"%s\" ", buf, ptr);
- if (rc <= 0)
+ if (rc <= 0) {
+ pclose(fp);
return -EOVERFLOW;
+ }
len += rc;
}