From 619f28077ce6cb27d19a7803faa72557e4ef9b57 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Tue, 10 Nov 2015 15:09:36 +0000 Subject: [PATCH] Plugging four memory leaks. git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5399 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 1 + src/files.c | 13 +++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index faa27234..d6127a56 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ 2015-11-10 Benno Schulenberg * src/winio.c (edit_draw): Skip a zero-length match only when there /is/ a match. Found with valgrind. This fixes Savannah bug #41908. + * src/files.c (do_lockfile, update_poshistory): Plug memory leaks. 2015-11-08 Benno Schulenberg * src/global.c (shortcut_init): Allow exiting from the file browser diff --git a/src/files.c b/src/files.c index 25c5aaac..220f978d 100644 --- a/src/files.c +++ b/src/files.c @@ -251,8 +251,8 @@ int delete_lockfile(const char *lockfilename) * complain to the user. */ int do_lockfile(const char *filename) { - char *lockdir = dirname((char *) mallocstrcpy(NULL, filename)); - char *lockbase = basename((char *) mallocstrcpy(NULL, filename)); + char *namecopy1 = (char *) mallocstrcpy(NULL, filename); + char *namecopy2 = (char *) mallocstrcpy(NULL, filename); size_t locknamesize = strlen(filename) + strlen(locking_prefix) + strlen(locking_suffix) + 3; char *lockfilename = charalloc(locknamesize); @@ -261,8 +261,10 @@ int do_lockfile(const char *filename) struct stat fileinfo; int lockfd, lockpid; - snprintf(lockfilename, locknamesize, "%s/%s%s%s", lockdir, - locking_prefix, lockbase, locking_suffix); + snprintf(lockfilename, locknamesize, "%s/%s%s%s", dirname(namecopy1), + locking_prefix, basename(namecopy2), locking_suffix); + free(namecopy1); + free(namecopy2); #ifdef DEBUG fprintf(stderr, "lock file name is %s\n", lockfilename); #endif @@ -309,8 +311,10 @@ int do_lockfile(const char *filename) if (stat(lockfiledir, &fileinfo) == -1) { statusbar(_("Error writing lock file: Directory \'%s\' doesn't exist"), lockfiledir); + free(lockfiledir); return 0; } + free(lockfiledir); } return write_lockfile(lockfilename, filename, FALSE); @@ -3155,6 +3159,7 @@ void update_poshistory(char *filename, ssize_t lineno, ssize_t xpos) if (!strcmp(posptr->filename, fullpath)) { posptr->lineno = lineno; posptr->xno = xpos; + free(fullpath); return; } posprev = posptr; -- 2.39.5