commit 3def429290f5920bcc4ce64f221bf210134e5c97
parent 803ea0d7a095450835e8151f326177135ab518bc
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Sun, 27 Mar 2022 12:34:32 +0200
tweaks: don't leave an orphaned temporary file behind when writing fails
Diffstat:
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/src/text.c b/src/text.c
@@ -2528,6 +2528,7 @@ void do_spell(void)
if (!okay) {
statusline(ALERT, _("Error writing temp file: %s"), strerror(errno));
+ unlink(temp_name);
free(temp_name);
return;
}
@@ -2924,13 +2925,10 @@ void do_formatter(void)
if (temp_name != NULL)
okay = write_file(temp_name, stream, TEMPORARY, OVERWRITE, NONOTES);
- if (!okay) {
+ if (!okay)
statusline(ALERT, _("Error writing temp file: %s"), strerror(errno));
- free(temp_name);
- return;
- }
-
- treat(temp_name, openfile->syntax->formatter, FALSE);
+ else
+ treat(temp_name, openfile->syntax->formatter, FALSE);
unlink(temp_name);
free(temp_name);