nano

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

commit c84a7697339a43c01f00d2f944e86b3efbb6c93c
parent e3ef7787562645251773212b4f7d2ee3805bb79b
Author: Benno Schulenberg <bensberg@telfort.nl>
Date:   Wed, 14 Jul 2021 10:06:04 +0200

memory: free any allocated strings, also in the emergency code path

Diffstat:
Msrc/nano.c | 12+++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/src/nano.c b/src/nano.c @@ -311,15 +311,16 @@ void do_exit(void) /* Save the current buffer under the given name (or under "nano.<PID>" * for a nameless buffer). If needed, the name is modified to be unique. */ -void emergency_save(char *plainname) +void emergency_save(const char *filename) { + char *plainname, *targetname; bool saved = FALSE; - char *targetname; - if (*plainname == '\0') { - plainname = nrealloc(plainname, 28); + if (*filename == '\0') { + plainname = nmalloc(28); sprintf(plainname, "nano.%u", getpid()); - } + } else + plainname = copy_of(filename); targetname = get_next_filename(plainname, ".save"); @@ -345,6 +346,7 @@ void emergency_save(char *plainname) #endif free(targetname); + free(plainname); } /* Die gracefully -- by restoring the terminal state and saving any buffers