From 9882f987cf0a39cde7ad3a4a3b7328f5725554dc Mon Sep 17 00:00:00 2001 From: Snaipe Date: Sun, 13 Sep 2015 13:12:16 +0200 Subject: [PATCH] Fixed memory leak on cr_assert() --- include/criterion/assert.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/include/criterion/assert.h b/include/criterion/assert.h index 62c578c..b3434a5 100644 --- a/include/criterion/assert.h +++ b/include/criterion/assert.h @@ -94,11 +94,14 @@ CR_END_C_API char *formatted_msg = NULL; \ int msglen = cr_asprintf(&formatted_msg, \ "" CR_VA_TAIL(CR_VA_TAIL(__VA_ARGS__))); \ - MsgVar = formatted_msg && *formatted_msg ? \ - formatted_msg : def_msg; \ - \ - if (!formatted_msg || !*formatted_msg) \ + if (formatted_msg && *formatted_msg) { \ + MsgVar = formatted_msg; \ + CR_STDN free(def_msg); \ + } else { \ + MsgVar = def_msg; \ msglen = strlen(def_msg); \ + CR_STDN free(formatted_msg); \ + } \ \ BufSize = sizeof(struct criterion_assert_stats) \ + sizeof (size_t) + msglen + 1; \