nano

nano with my custom patches
git clone git://bsandro.tech/nano
Log | Files | Refs | README | LICENSE

commit e64c9508962cc87d3efe16387f20caa59aecb1b1
parent 69b12d907eeceabbe6e7ce157a6709727c5998ce
Author: Benno Schulenberg <bensberg@telfort.nl>
Date:   Fri, 26 Jun 2020 10:24:52 +0200

tweaks: close opened files when something goes wrong  [coverity]

Diffstat:
Msrc/files.c | 4++++
1 file changed, 4 insertions(+), 0 deletions(-)

diff --git a/src/files.c b/src/files.c @@ -1674,6 +1674,7 @@ bool write_file(const char *name, FILE *thefile, bool tmp, * be fond of backups. Thus, without one, do not go on. */ if (*backupname == '\0') { statusline(ALERT, _("Too many existing backup files")); + fclose(original); goto cleanup_and_exit; } } @@ -1681,6 +1682,7 @@ bool write_file(const char *name, FILE *thefile, bool tmp, /* Now first try to delete an existing backup file. */ if (unlink(backupname) < 0 && errno != ENOENT && !ISSET(INSECURE_BACKUP)) { warn_and_briefly_pause(_("Cannot delete existing backup")); + fclose(original); if (user_wants_to_proceed()) goto skip_backup; statusline(HUSH, _("Cannot delete backup %s: %s"), @@ -1701,6 +1703,7 @@ bool write_file(const char *name, FILE *thefile, bool tmp, if (backup_file == NULL) { warn_and_briefly_pause(_("Cannot create backup file")); + fclose(original); if (user_wants_to_proceed()) goto skip_backup; statusline(HUSH, _("Cannot create backup %s: %s"), @@ -1765,6 +1768,7 @@ bool write_file(const char *name, FILE *thefile, bool tmp, if (tempname == NULL) { statusline(ALERT, _("Error writing temp file: %s"), strerror(errno)); + fclose(source); goto cleanup_and_exit; }