From b923260d82038e8619a71c5d8d4745b919f739f1 Mon Sep 17 00:00:00 2001 From: Moritz Grimm Date: Wed, 12 Feb 2020 00:39:13 +0100 Subject: [PATCH] mdata_destroy() is supposed to be idempotent --- src/mdata.c | 3 ++- tests/check_mdata.c | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/mdata.c b/src/mdata.c index f36e6e6..403097b 100644 --- a/src/mdata.c +++ b/src/mdata.c @@ -277,7 +277,8 @@ mdata_destroy(struct mdata **md_p) { struct mdata *md = *md_p; - _mdata_clear(md); + if (md) + _mdata_clear(md); xfree(md); *md_p = NULL; } diff --git a/tests/check_mdata.c b/tests/check_mdata.c index bd5f4aa..ac06501 100644 --- a/tests/check_mdata.c +++ b/tests/check_mdata.c @@ -193,6 +193,7 @@ setup_checked(void) void teardown_checked(void) { + mdata_destroy(&md); mdata_destroy(&md); ck_assert_ptr_eq(md, NULL);