fix some more occurrences of potential errno clobbering
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
diff --git a/lib/buf.c b/lib/buf.c
index 32d933f..eb235b0 100644
--- a/lib/buf.c
+++ b/lib/buf.c
@@ -294,10 +294,11 @@ buf_write(BUF *b, const char *path, mode_t mode)
int fd;
open:
if ((fd = open(path, O_WRONLY|O_CREAT|O_TRUNC, mode)) == -1) {
+ err = got_error_from_errno2("open", path);
if (errno == EACCES && unlink(path) != -1)
goto open;
else
- return got_error_from_errno2("open", path);
+ return err;
}
if (buf_write_fd(b, fd) == -1) {
diff --git a/lib/commit_graph.c b/lib/commit_graph.c
index 05aa9d3..9b907af 100644
--- a/lib/commit_graph.c
+++ b/lib/commit_graph.c
@@ -404,8 +404,9 @@ got_commit_graph_open(struct got_commit_graph **graph,
*graph = alloc_graph(path);
if (*graph == NULL) {
+ err = got_error_from_errno("alloc_graph");
got_object_commit_close(commit);
- return got_error_from_errno("alloc_graph");
+ return err;
}
if (first_parent_traversal)
diff --git a/lib/path.c b/lib/path.c
index a8c3780..8ae1c96 100644
--- a/lib/path.c
+++ b/lib/path.c
@@ -401,6 +401,7 @@ got_path_strip_trailing_slashes(char *path)
const struct got_error *
got_path_find_prog(char **filename, const char *prog)
{
+ const struct got_error *err = NULL;
char *p;
int len;
struct stat sbuf;
@@ -436,8 +437,9 @@ got_path_find_prog(char **filename, const char *prog)
p[--len] = '\0'; /* strip trailing '/' */
if (asprintf(filename, "%s/%s", p, prog) == -1) {
+ err = got_error_from_errno("asprintf");
free(path);
- return got_error_from_errno("asprintf");
+ return err;
}
if ((stat(*filename, &sbuf) == 0) && S_ISREG(sbuf.st_mode) &&
access(*filename, X_OK) == 0) {