From 39fca79b2100584adb6fc7a90327e053029f5c26 Mon Sep 17 00:00:00 2001 From: Chris Allegretta Date: Sun, 15 Nov 2015 06:43:54 +0000 Subject: [PATCH] Backport of r5338 - r5340 from trunk. git-svn-id: svn://svn.savannah.gnu.org/nano/branches/nano_2_4_branch@5412 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 9 +++++++++ src/files.c | 19 +++++++++++++------ src/rcfile.c | 2 +- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index a68a072d..97250dc2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2015-08-03 Benno Schulenberg + * src/rcfile.c (parse_binding): Check the value of shortcut->toggle + only if it actually is a toggle. Found with valgrind. + * src/files.c (write_lockfile): Plug a leak. Found with valgrind. + +2015-08-02 Benno Schulenberg + * src/files.c (initialize_buffer): Initialize also openfile->syntax. + This addresses Debian bug #787914 reported by Paul Wise. + 2015-08-01 Benno Schulenberg * src/nano.c (precalc_multicolorinfo): Set each multiline-color value instead of OR-ing it. This fixes Savannah bug #45640. diff --git a/src/files.c b/src/files.c index 582ef714..5229de68 100644 --- a/src/files.c +++ b/src/files.c @@ -83,6 +83,7 @@ void initialize_buffer(void) openfile->lock_filename = NULL; #endif #ifndef DISABLE_COLOR + openfile->syntax = NULL; openfile->colorstrings = NULL; #endif } @@ -137,19 +138,19 @@ int write_lockfile(const char *lockfilename, const char *origfilename, bool modi myuid = geteuid(); if ((mypwuid = getpwuid(myuid)) == NULL) { statusbar(_("Couldn't determine my identity for lock file (getpwuid() failed)")); - return -1; + goto free_and_fail; } mypid = getpid(); if (gethostname(myhostname, 31) < 0) { statusbar(_("Couldn't determine hostname for lock file: %s"), strerror(errno)); - return -1; + goto free_and_fail; } /* Check if the lock exists before we try to delete it...*/ if (stat(lockfilename, &fileinfo) != -1) if (delete_lockfile(lockfilename) < 0) - return -1; + goto free_and_fail; if (ISSET(INSECURE_BACKUP)) cflags = O_WRONLY | O_CREAT | O_APPEND; @@ -164,6 +165,7 @@ int write_lockfile(const char *lockfilename, const char *origfilename, bool modi if (fd < 0) { statusbar(_("Error writing lock file %s: %s"), lockfilename, strerror(errno)); + free(lockdata); return 0; } @@ -174,7 +176,7 @@ int write_lockfile(const char *lockfilename, const char *origfilename, bool modi if (fd < 0 || filestream == NULL) { statusbar(_("Error writing lock file %s: %s"), lockfilename, strerror(errno)); - return -1; + goto free_and_fail; } /* Okay, so at the moment we're following this state for how to @@ -211,7 +213,7 @@ int write_lockfile(const char *lockfilename, const char *origfilename, bool modi if (wroteamt < lockdatalen) { statusbar(_("Error writing lock file %s: %s"), lockfilename, ferror(filestream)); - return -1; + goto free_and_fail; } #ifdef DEBUG @@ -221,12 +223,17 @@ int write_lockfile(const char *lockfilename, const char *origfilename, bool modi if (fclose(filestream) == EOF) { statusbar(_("Error writing lock file %s: %s"), lockfilename, strerror(errno)); - return -1; + goto free_and_fail; } openfile->lock_filename = (char *) lockfilename; + free(lockdata); return 1; + + free_and_fail: + free(lockdata); + return -1; } /* Less exciting, delete the lockfile. Return -1 if unsuccessful and diff --git a/src/rcfile.c b/src/rcfile.c index d52e0a8c..13740308 100644 --- a/src/rcfile.c +++ b/src/rcfile.c @@ -562,7 +562,7 @@ void parse_binding(char *ptr, bool dobind) /* If this is a toggle, copy its sequence number. */ if (newsc->scfunc == do_toggle_void) { for (s = sclist; s != NULL; s = s->next) - if (newsc->toggle == s->toggle) + if (s->scfunc == do_toggle_void && s->toggle == newsc->toggle) newsc->ordinal = s->ordinal; } else newsc->ordinal = 0; -- 2.39.5