shithub: puzzles

Download patch

ref: bb31efdbc91495a4385ca0afffa4c8bb8f564d7b
parent: c139aba078f2ec46a0e0b44142b7c982519a8263
author: Ben Harris <[email protected]>
date: Mon Feb 13 04:31:03 EST 2023

Fix memory leaks in Keen's validate_desc()

Keen uses a DSF to validate its game descriptions and almost always
failed to free it, even when the validation succeeded.

--- a/keen.c
+++ b/keen.c
@@ -1310,8 +1310,10 @@
 	return ret;
     }
 
-    if (*p != ',')
+    if (*p != ',') {
+        sfree(dsf);
 	return "Expected ',' after block structure description";
+    }
     p++;
 
     /*
@@ -1323,11 +1325,15 @@
 	    if (*p == 'a' || *p == 'm') {
 		/* these clues need no validation */
 	    } else if (*p == 'd' || *p == 's') {
-		if (dsf_size(dsf, i) != 2)
+		if (dsf_size(dsf, i) != 2) {
+                    sfree(dsf);
 		    return "Subtraction and division blocks must have area 2";
+                }
 	    } else if (!*p) {
+                sfree(dsf);
 		return "Too few clues for block structure";
 	    } else {
+                sfree(dsf);
 		return "Unrecognised clue type";
 	    }
 	    p++;
@@ -1334,6 +1340,7 @@
 	    while (*p && isdigit((unsigned char)*p)) p++;
 	}
     }
+    sfree(dsf);
     if (*p)
 	return "Too many clues for block structure";