From 60641ca499136ccf64ad081b9e783dacf45082e9 Mon Sep 17 00:00:00 2001 From: Murilo Pereira Date: Sat, 12 Feb 2011 01:26:03 -0200 Subject: [PATCH] Avoid dereferencing NULL pointers. --- lib/card.c | 4 +++- lib/deck.c | 28 ++++++++++++++-------------- lib/frame.c | 4 +++- lib/stack.c | 4 +++- 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/lib/card.c b/lib/card.c index f43d6ba..28073aa 100644 --- a/lib/card.c +++ b/lib/card.c @@ -26,7 +26,9 @@ void initialize_card(struct card *card) { } void delete_card(struct card *card) { - delete_frame(card->frame); + if (card) { + delete_frame(card->frame); + } free(card); return; diff --git a/lib/deck.c b/lib/deck.c index ac8305a..8ad7697 100644 --- a/lib/deck.c +++ b/lib/deck.c @@ -51,22 +51,22 @@ void initialize_deck(struct deck *deck) { } void delete_deck(struct deck *deck) { - delete_stack(deck->stock); - delete_stack(deck->waste_pile); + if (deck) { + delete_stack(deck->waste_pile); - delete_stack(deck->foundation_0); - delete_stack(deck->foundation_1); - delete_stack(deck->foundation_2); - delete_stack(deck->foundation_3); - - delete_stack(deck->maneuvre_0); - delete_stack(deck->maneuvre_1); - delete_stack(deck->maneuvre_2); - delete_stack(deck->maneuvre_3); - delete_stack(deck->maneuvre_4); - delete_stack(deck->maneuvre_5); - delete_stack(deck->maneuvre_6); + delete_stack(deck->foundation_0); + delete_stack(deck->foundation_1); + delete_stack(deck->foundation_2); + delete_stack(deck->foundation_3); + delete_stack(deck->maneuvre_0); + delete_stack(deck->maneuvre_1); + delete_stack(deck->maneuvre_2); + delete_stack(deck->maneuvre_3); + delete_stack(deck->maneuvre_4); + delete_stack(deck->maneuvre_5); + delete_stack(deck->maneuvre_6); + } free(deck); return; diff --git a/lib/frame.c b/lib/frame.c index 427576d..8eb7c60 100644 --- a/lib/frame.c +++ b/lib/frame.c @@ -23,7 +23,9 @@ void initialize_frame(struct frame *frame) { } void delete_frame(struct frame *frame) { - delwin(frame->shape); + if (frame) { + delwin(frame->shape); + } free(frame); return; diff --git a/lib/stack.c b/lib/stack.c index fd89986..f90ebfa 100644 --- a/lib/stack.c +++ b/lib/stack.c @@ -29,7 +29,9 @@ void initialize_stack(struct stack *stack) { } void delete_stack(struct stack *stack) { - delete_card(stack->card); + if (stack) { + delete_card(stack->card); + } free(stack); return;