Commit 2309852
committed
loose: avoid closing invalid fd on error path
write_one_object() opens a file at line 186 and jumps to the
errout label on failure. The errout cleanup unconditionally calls
close(fd), but when open() itself failed, fd is -1. Calling
close(-1) is harmless on most platforms (returns EBADF) but is
undefined behavior per POSIX and can confuse fd tracking in
sanitizer builds.
Guard the close with fd >= 0.
Pointed out by Coverity.
Assisted-by: Claude Opus 4.6
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>1 parent 55ad7e9 commit 2309852
1 file changed
Lines changed: 2 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
203 | 203 | | |
204 | 204 | | |
205 | 205 | | |
206 | | - | |
| 206 | + | |
| 207 | + | |
207 | 208 | | |
208 | 209 | | |
209 | 210 | | |
| |||
0 commit comments