From 19401e95e0a75577103e9c1a877611234a0d8ab5 Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Mon, 13 Feb 2023 11:08:14 +0000 Subject: [PATCH] Don't leak duplicate edges in Untangle Untangle game descriptions are allowed to contain duplicate edges, and add234() can handle deduping them. However, when add234() reports that your newly-allocated edge is a duplicate, it's important to free it again. --- untangle.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/untangle.c b/untangle.c index 1dc4fb3..34924ae 100644 --- a/untangle.c +++ b/untangle.c @@ -420,7 +420,9 @@ static void addedge(tree234 *edges, int a, int b) e->a = min(a, b); e->b = max(a, b); - add234(edges, e); + if (add234(edges, e) != e) + /* Duplicate edge. */ + sfree(e); } static bool isedge(tree234 *edges, int a, int b)