ed: Fix double-free

After join() is called for the first time, s.str is left pointing
to a string that was just freed. Upon the second call to join(),
it is freed again at the start of the function.

Since the string is reset on every function call, there is no reason
for it to be static, so just replace the initial free with assignment
to NULL.
This commit is contained in:
Cág 2020-10-19 16:41:01 -04:00 committed by Michael Forney
parent 172cdd98c3
commit 3eb89c44aa
1 changed files with 2 additions and 2 deletions

4
ed.c
View File

@ -839,9 +839,9 @@ join(void)
{
int i;
char *t, c;
static String s;
String s;
free(s.str);
s.str = NULL;
s.siz = s.cap = 0;
for (i = line1;; i = nextln(i)) {
for (t = gettxt(i); (c = *t) != '\n'; ++t)