shithub: puzzles

Download patch

ref: 19401e95e0a75577103e9c1a877611234a0d8ab5
parent: 0a7c531e8f4c1970662f7c30aea006e65d5ff010
author: Ben Harris <bjh21@bjh21.me.uk>
date: Mon Feb 13 06:08:14 EST 2023

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.

--- a/untangle.c
+++ b/untangle.c
@@ -420,7 +420,9 @@
     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)