commit 64470722a2a80a6b9144a79a162e11e8a0c2b7fb
parent d5d0d662f6a48cf922d524b0df11911bde263fac
Author: remph <lhr@disroot.org>
Date: Wed, 9 Apr 2025 16:15:48 +0100
Fix double free in swtch.c
The `list' pointer should be reset to NULL after the memory it points to
has been freed, otherwise the next time cleanswtch() is called it iterates
over the list starting at freed memory.
Diffstat:
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/cmd/scc-cc/cc2/swtch.c b/src/cmd/scc-cc/cc2/swtch.c
@@ -5,7 +5,7 @@
#include "cc2.h"
-static Swtch *list;
+static Swtch *list = NULL;
static Node *
swtch_if(Node *np)
@@ -147,4 +147,5 @@ cleanswtch(void)
}
free(p);
}
+ list = NULL;
}