[scc-dev] [PATCH] Fix double free in swtch.c

From: remph <lhr_at_disroot.org>
Date: Wed, 9 Apr 2025 16:15:48 +0100

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.

---
 src/cmd/scc-cc/cc2/swtch.c | 3 ++-
 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
index 157c0969..3176e819 100644
--- a/src/cmd/scc-cc/cc2/swtch.c
+++ b/src/cmd/scc-cc/cc2/swtch.c
_at_@ -5,7 +5,7 @@
 
 #include "cc2.h"
 
-static Swtch *list;
+static Swtch *list = NULL;
 
 static Node *
 swtch_if(Node *np)
_at_@ -147,4 +147,5 @@ cleanswtch(void)
 		}
 		free(p);
 	}
+	list = NULL;
 }
-- 
2.48.1
--
To unsubscribe send a mail to scc-dev+unsubscribe_at_simple-cc.org
Received on Wed 09 Apr 2025 - 17:15:48 CEST

This archive was generated by hypermail 2.3.0 : Wed 09 Apr 2025 - 17:20:01 CEST