# HG changeset patch # User Markus Bröker # Date 1243522312 -7200 # Node ID 810acedf60d8fc2f90b4914b42d0259ccd1f8b60 # Parent d2a071bd1a60ed69714d48ff38bebae20c13c5c1 alpha_beta: memory leaks After fixing all the memory leaks in this piece code, i can finally go further to implement a better KI. committer: Markus Bröker diff --git a/alpha_beta.c b/alpha_beta.c --- a/alpha_beta.c +++ b/alpha_beta.c @@ -74,7 +74,6 @@ board[stack_end->data->target] = EMPTY; actual = stack_end->prev; - free (stack_end->data); free (stack_end); stack_end = actual; @@ -227,14 +226,21 @@ undo (); t++; - if (moveValue >= beta) + if (moveValue >= beta) { + free (move); return beta; + } if (moveValue > alpha) { alpha = moveValue; - if (depth == desired_depth) + if (depth == desired_depth) { + if (bestMove != NULL) + free (bestMove); bestMove = move; + continue; + } } + free (move); } return alpha; @@ -264,6 +270,7 @@ moveValue = max_alpha_beta (depth - 1, alpha, beta); undo (); + free (move); t++; if (moveValue <= alpha) @@ -338,6 +345,7 @@ } board[bestMove->target] = 'O'; + free (bestMove); print (); if ((estimateFunction () * estimateFunction ()) == 2500) {