nano

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

commit 94347f081107e1061b4ddb88986f61da4baff021
parent 1a4a3de68bfa3ffcde720f3c1a1b641df127d9e8
Author: Benno Schulenberg <bensberg@telfort.nl>
Date:   Sun, 22 Apr 2018 12:00:26 +0200

memory: use a reallocation to reduce the amount of leakage

Diffstat:
Msrc/text.c | 13+++++--------
1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/src/text.c b/src/text.c @@ -2509,16 +2509,13 @@ void do_full_justify(void) void construct_argument_list(char ***arguments, char *command, char *filename) { char *copy_of_command = mallocstrcpy(NULL, command); - char *element; - size_t length = 3; + char *element = strtok(copy_of_command, " "); + size_t length = 2; - *arguments = (char **)nmalloc(length * sizeof(char *)); - (*arguments)[0] = strtok(copy_of_command, " "); - - while ((element = strtok(NULL, " ")) != NULL) { - length++; - *arguments = (char **)nrealloc(*arguments, length * sizeof(char *)); + while (element != NULL) { + *arguments = (char **)nrealloc(*arguments, ++length * sizeof(char *)); (*arguments)[length - 3] = element; + element = strtok(NULL, " "); } (*arguments)[length - 2] = filename;