aboutsummaryrefslogtreecommitdiff
path: root/untangle.c
diff options
context:
space:
mode:
authorBen Harris <bjh21@bjh21.me.uk>2023-02-13 11:08:14 +0000
committerBen Harris <bjh21@bjh21.me.uk>2023-02-13 11:08:14 +0000
commit19401e95e0a75577103e9c1a877611234a0d8ab5 (patch)
tree08e5fd3519b2bd4e147e43c9ca7846e9ce7fd373 /untangle.c
parent0a7c531e8f4c1970662f7c30aea006e65d5ff010 (diff)
downloadpuzzles-19401e95e0a75577103e9c1a877611234a0d8ab5.zip
puzzles-19401e95e0a75577103e9c1a877611234a0d8ab5.tar.gz
puzzles-19401e95e0a75577103e9c1a877611234a0d8ab5.tar.bz2
puzzles-19401e95e0a75577103e9c1a877611234a0d8ab5.tar.xz
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.
Diffstat (limited to 'untangle.c')
-rw-r--r--untangle.c4
1 files changed, 3 insertions, 1 deletions
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)