diff options
Diffstat (limited to 'csol.c')
-rw-r--r-- | csol.c | 41 |
1 files changed, 35 insertions, 6 deletions
@@ -86,7 +86,7 @@ static void Shuffle(Deck deck) { int f; - for(f = 0; f < 500; f++) + for(f = 0; f < 1000; f++) { int c1 = rand() % 52; int c2 = rand() % 52; @@ -106,7 +106,7 @@ static void AddToPile(Pile *pile, Card card) if (!pile->card) { - Fatal("Failled to reallocate memory"); + Fatal("Failed to reallocate memory"); } else { @@ -122,7 +122,7 @@ static void InsertBottomOfPile(Pile *pile, Card card) if (!pile->card) { - Fatal("Failled to reallocate memory"); + Fatal("Failed to reallocate memory"); } else { @@ -147,11 +147,19 @@ static Card PopPile(Pile *pile) pile->no--; - pile->card = realloc(pile->card, sizeof *pile->card * pile->no); + if (pile->no) + { + pile->card = realloc(pile->card, sizeof *pile->card * pile->no); - if (!pile->card) + if (!pile->card) + { + Fatal("Failed to reallocate memory"); + } + } + else { - Fatal("Failled to reallocate memory"); + free(pile->card); + pile->card = NULL; } } else @@ -195,6 +203,15 @@ static void SwapPile(Pile *a, Pile *b) *b = t; } +static void FreePile(Pile *p) +{ + if (p->card) + { + free(p->card); + p->card = NULL; + } +} + static void Centre(int y, const char *p) { size_t l = strlen(p); @@ -796,6 +813,18 @@ static void Klondike(int draw) { WinScreen(); } + + FreePile(&pile); + FreePile(&turned); + FreePile(&hearts); + FreePile(&diamonds); + FreePile(&clubs); + FreePile(&spades); + for(f = 0; f < 7; f++) + { + FreePile(&column_down[f]); + FreePile(&column_up[f]); + } } int main(int argc, char *argv[]) |