Hi, I'm new using CUnit, but I think that or it has memory leaks, or I'm not using it in the right way.
To reproduce these leaks, i used this file:
// cunit.c
#include "CUnit/Basic.h"
#include "CUnit/Console.h"
#include "CUnit/Automated.h"
CU_ErrorCode test_debug(CU_pSuite suite);
int before_all(void){ return 0; }
int after_all(void){ return 0; }
void test_assert_equal(){
CU_ASSERT_EQUAL(1, 1);
CU_ASSERT_NOT_EQUAL(1, 2);
}
void test_assert_string_equal(){
CU_ASSERT_STRING_EQUAL("1", "1");
CU_ASSERT_STRING_NOT_EQUAL("1", "2");
}
CU_ErrorCode test_debug(CU_pSuite suite){
suite = CU_add_suite("Simple test to check with Valgrind if CUnit has memory leaks", before_all, after_all);
if(suite == NULL){
CU_cleanup_registry();
return CU_get_error();
}
if(
( CU_add_test(suite, "assert equal ", test_assert_equal ) == NULL ) ||
( CU_add_test(suite, "assert string equal", test_assert_string_equal ) == NULL )
){
CU_cleanup_registry();
return CU_get_error();
}
return CUE_SUCCESS;
}
int main(){
CU_pSuite suite = NULL;
CU_ErrorCode status_code;
if(CU_initialize_registry() != CUE_SUCCESS) return CU_get_error();
status_code = test_debug(suite);
if(status_code != CUE_SUCCESS) return status_code;
CU_basic_set_mode(CU_BRM_VERBOSE);
CU_basic_run_tests();
CU_basic_show_failures(CU_get_failure_list());
CU_cleanup_registry();
return CU_get_error();
}
So, I compiled it:
gcc -g -lcunit -o test cunit.c -Wall
And executed with Valgrind:
valgrind --show-reachable=yes --tool=memcheck --leak-check=yes ./test 2>> valgrind.log
I had the following summary on valgrind.log:
LEAK SUMMARY:
definitely lost: 80 bytes in 1 blocks
indirectly lost: 116 bytes in 4 blocks
possibly lost: 0 bytes in 0 blocks
still reachable: 41,831 bytes in 266 blocks
suppressed: 16,861 bytes in 91 blocks
Am I doing something wrong here with CUnit or Valgrind, or CUnit has memory leaks?
I'm using:
Mac OX 10.8.5
CUnit stable 2.1-2 (installed with Homebrew)
Valgrind stable 3.9.0, HEAD (installed with Homebrew)
I know that Valgrind support on MacOS 10.8 is experimental... This bug is related to it?
I'm sending my valgrind.log as attachment.
Anonymous
Up