From a5dd3b6b102d15d420d51d3d229b6e696fec9c2e Mon Sep 17 00:00:00 2001 From: Gautier Pelloux-Prayer Date: Thu, 3 Mar 2016 15:43:49 +0100 Subject: [PATCH] tester.c: fix memory leaks detector --- tester/tester.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/tester/tester.c b/tester/tester.c index e75d03191..c1b5b4764 100644 --- a/tester/tester.c +++ b/tester/tester.c @@ -551,18 +551,21 @@ int liblinphone_tester_after_each(void) { ms_error("%s", format); all_leaks_buffer = ms_strcat_printf(all_leaks_buffer, "\n%s", format); + } - { - //prevent any future leaks - const char **tags = bc_tester_current_test_tags(); - // if the test is NOT marked as leaking memory and it actually is, we should make it fail - if ( tags && - !((tags[0] && strcmp(tags[0], "LeakingMemory")) || (tags[1] && strcmp(tags[1], "LeakingMemory")))) { - BC_FAIL("This test is leaking memory!"); - return 1; - } + // prevent any future leaks + { + const char **tags = bc_tester_current_test_tags(); + int leaks_expected = + (tags && ((tags[0] && !strcmp(tags[0], "LeaksMemory")) || (tags[1] && !strcmp(tags[1], "LeaksMemory")))); + // if the test is NOT marked as leaking memory and it actually is, we should make it fail + if (!leaks_expected && leaked_objects > 0) { + BC_FAIL("This test is leaking memory!"); + // and reciprocally + } else if (leaks_expected && leaked_objects == 0) { + BC_FAIL("This test is not leaking anymore, please remove LeaksMemory tag!"); + return 1; } - } }