memory: use a reallocation to reduce the amount of leakage
parent
1a4a3de68b
commit
94347f0811
13
src/text.c
13
src/text.c
|
@ -2509,16 +2509,13 @@ void do_full_justify(void)
|
||||||
void construct_argument_list(char ***arguments, char *command, char *filename)
|
void construct_argument_list(char ***arguments, char *command, char *filename)
|
||||||
{
|
{
|
||||||
char *copy_of_command = mallocstrcpy(NULL, command);
|
char *copy_of_command = mallocstrcpy(NULL, command);
|
||||||
char *element;
|
char *element = strtok(copy_of_command, " ");
|
||||||
size_t length = 3;
|
size_t length = 2;
|
||||||
|
|
||||||
*arguments = (char **)nmalloc(length * sizeof(char *));
|
while (element != NULL) {
|
||||||
(*arguments)[0] = strtok(copy_of_command, " ");
|
*arguments = (char **)nrealloc(*arguments, ++length * sizeof(char *));
|
||||||
|
|
||||||
while ((element = strtok(NULL, " ")) != NULL) {
|
|
||||||
length++;
|
|
||||||
*arguments = (char **)nrealloc(*arguments, length * sizeof(char *));
|
|
||||||
(*arguments)[length - 3] = element;
|
(*arguments)[length - 3] = element;
|
||||||
|
element = strtok(NULL, " ");
|
||||||
}
|
}
|
||||||
|
|
||||||
(*arguments)[length - 2] = filename;
|
(*arguments)[length - 2] = filename;
|
||||||
|
|
Loading…
Reference in New Issue