Couple of minor updates to restore accuracy.
[sgt/puzzles] / inertia.c
index a158363..95bdcc8 100644 (file)
--- a/inertia.c
+++ b/inertia.c
@@ -221,6 +221,9 @@ static struct solver_scratch *new_scratch(int w, int h)
 
 static void free_scratch(struct solver_scratch *sc)
 {
+    sfree(sc->reachable_from);
+    sfree(sc->reachable_to);
+    sfree(sc->positions);
     sfree(sc);
 }
 
@@ -370,7 +373,9 @@ static int find_gem_candidates(int w, int h, char *grid,
                    d2 = n;
                }
                i2 = (y2*w+x2)*DIRECTIONS+d2;
-               if (!reachable[i2]) {
+               if (x2 >= 0 && x2 < w &&
+                   y2 >= 0 && y2 < h &&
+                   !reachable[i2]) {
                    int ok;
 #ifdef SOLVER_DIAGNOSTICS
                    printf("  trying point %d,%d,%d", x2, y2, d2);
@@ -938,6 +943,8 @@ static game_drawstate *game_new_drawstate(drawing *dr, game_state *state)
 
 static void game_free_drawstate(drawing *dr, game_drawstate *ds)
 {
+    if (ds->player_background)
+       blitter_free(dr, ds->player_background);
     sfree(ds->grid);
     sfree(ds);
 }