diff options
| author | Ron Yorston <rmy@pobox.com> | 2025-07-30 12:26:23 +0100 |
|---|---|---|
| committer | Ron Yorston <rmy@pobox.com> | 2025-07-30 12:26:23 +0100 |
| commit | 3ddcebe75d5cb062eb84a8fb92ec0e7554ed3d05 (patch) | |
| tree | 706455dec8f5078e1faad42ee241950fbf91cf76 | |
| parent | 1f6926252ec11037b06e29791920e6c13d169520 (diff) | |
| download | busybox-w32-3ddcebe75d5cb062eb84a8fb92ec0e7554ed3d05.tar.gz busybox-w32-3ddcebe75d5cb062eb84a8fb92ec0e7554ed3d05.tar.bz2 busybox-w32-3ddcebe75d5cb062eb84a8fb92ec0e7554ed3d05.zip | |
sed: ensure temporary file is deleted on error
It wasn't possible to delete the temporary output file in
case of error on Windows because it was open.
Close the file before trying to unlink it.
Adds 16 bytes.
(GitHub issue #509)
| -rw-r--r-- | editors/sed.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/editors/sed.c b/editors/sed.c index 107e664a0..204417108 100644 --- a/editors/sed.c +++ b/editors/sed.c | |||
| @@ -257,7 +257,12 @@ static FILE *sed_xfopen_w(const char *fname) | |||
| 257 | 257 | ||
| 258 | static void cleanup_outname(void) | 258 | static void cleanup_outname(void) |
| 259 | { | 259 | { |
| 260 | if (G.outname) unlink(G.outname); | 260 | if (G.outname) { |
| 261 | #if ENABLE_PLATFORM_MINGW32 | ||
| 262 | fclose(G.nonstdout); | ||
| 263 | #endif | ||
| 264 | unlink(G.outname); | ||
| 265 | } | ||
| 261 | } | 266 | } |
| 262 | 267 | ||
| 263 | /* strcpy, replacing "\from" with 'to'. If to is NUL, replacing "\any" with 'any' */ | 268 | /* strcpy, replacing "\from" with 'to'. If to is NUL, replacing "\any" with 'any' */ |
