Skip to content

Commit

Permalink
Restore errno after closing failed FD
Browse files Browse the repository at this point in the history
Ref: #440

`close(fd)` resets `errno`, so when we return with a failure,
the original error cause is lost.
  • Loading branch information
byroot committed Apr 3, 2023
1 parent 7639d0d commit 57988b9
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ext/bootsnap/bootsnap.c
Expand Up @@ -377,7 +377,9 @@ open_current_file(char * path, struct bs_cache_key * key, const char ** errno_pr

if (fstat(fd, &statbuf) < 0) {
*errno_provenance = "bs_fetch:open_current_file:fstat";
int previous_errno = errno;
close(fd);
errno = previous_errno;
return -1;
}

Expand Down

0 comments on commit 57988b9

Please sign in to comment.