fix memory leak
authorLaurent Mazet <mazet@softndesign.org>
Thu, 18 Jul 2024 21:38:20 +0000 (23:38 +0200)
committerLaurent Mazet <mazet@softndesign.org>
Thu, 18 Jul 2024 21:38:20 +0000 (23:38 +0200)
function.c
makefile

index cd5302510e52976e4c48610c05906640b50107eb..d090d168af683ff54a3befd2b6c4691eed6343de 100644 (file)
@@ -57,11 +57,10 @@ board_t *initplay (board_t *board)
 
 board_t *copyboard (board_t *board)
 {
-    board_t *newboard = (board_t *) malloc (sizeof (board_t));
-    CHECKALLOC (board);
+    board_t *newboard = initboard (board->width, board->height);
+    char *tab = newboard->tab;
     memcpy (newboard, board, sizeof (board_t));
-    newboard->tab = (char *) calloc (1, board->width * board->height + 1);
-    CHECKALLOC (newboard->tab);
+    newboard->tab = tab;
     memcpy (newboard->tab, board->tab, board->width * board->height + 1);
     return newboard;
 }
@@ -535,7 +534,7 @@ board_t *popcache (cache_t *cache, int *xcursor, int *ycursor, int *opt)
 void emptycache (cache_t *cache)
 {
     while (cache->board != NULL) {
-        free (cache->board);
+        freeboard (cache->board);
         cache->board = NULL;
         cache++;
     }
index 3f2fd9558c752cd6614b0e48ab6acfbc43dc1096..d6dd76fb3baccb5d3fe63d144902e5b5727b0f7c 100644 (file)
--- a/makefile
+++ b/makefile
@@ -79,7 +79,9 @@ purge: clean
        rm -f purge $(ALLEXE:%=%.exe)
        $(call PASS, SUCCESS)
 
-valgrinds: all
+valgrinds:
+       export LDOPTS="test.o"; \
+       $(MAKE) test.o all
        $(MAKE) $(addprefix valgrind_,$(ALLEXE))
 
 wipe: purge