Commit d81b70f1 authored by Gautier Pelloux-Prayer's avatar Gautier Pelloux-Prayer
Browse files

tester: fix memory leaks and invalid read/writes

parent 30306df8
......@@ -73,14 +73,14 @@ void belle_sip_object_dump_active_objects(void){
belle_sip_list_t *elem;
if (all_objects){
belle_sip_message("List of leaked objects:");
belle_sip_warning("List of leaked objects:");
for(elem=all_objects;elem!=NULL;elem=elem->next){
belle_sip_object_t *obj=(belle_sip_object_t*)elem->data;
char* content= belle_sip_object_to_string(obj);
belle_sip_message("%s(%p) ref=%i, content [%10s...]",obj->vptr->type_name,obj,obj->ref,content);
belle_sip_warning("%s(%p) ref=%i, content [%10s...]",obj->vptr->type_name,obj,obj->ref,content);
belle_sip_free(content);
}
}else belle_sip_message("No objects leaked.");
}else belle_sip_warning("No objects leaked.");
}
belle_sip_object_t * _belle_sip_object_new(size_t objsize, belle_sip_object_vptr_t *vptr){
......
......@@ -197,6 +197,7 @@ void belle_sip_tester_before_each() {
void belle_sip_tester_after_each() {
int leaked_objects = belle_sip_object_get_object_count() - leaked_objects_count;
BC_ASSERT_EQUAL(leaked_objects, 0, int, "%d");
if (leaked_objects > 0) {
belle_sip_object_dump_active_objects();
belle_sip_error("%d objects were leaked in latest test, please fix that!\n", leaked_objects);
......
......@@ -171,11 +171,11 @@ static void suite_complete_message_handler(const CU_pSuite pSuite, const CU_pFai
static time_t test_start_time = 0;
static void test_start_message_handler(const CU_pTest pTest, const CU_pSuite pSuite) {
int suite_index = bc_tester_suite_index(pSuite->pName);
bc_tester_printf(bc_printf_verbosity_info,"Suite [%s] Test [%s] started", pSuite->pName,pTest->pName);
test_start_time = time(NULL);
if (test_suite[suite_index]->before_each) {
test_suite[suite_index]->before_each();
}
bc_tester_printf(bc_printf_verbosity_info,"Suite [%s] Test [%s] started", pSuite->pName,pTest->pName);
test_start_time = time(NULL);
}
/*derivated from cunit*/
......@@ -187,10 +187,6 @@ static void test_complete_message_handler(const CU_pTest pTest, const CU_pSuite
char buffer[2048]={0};
CU_pFailureRecord pFailure = pFailureList;
if (test_suite[suite_index]->after_each) {
test_suite[suite_index]->after_each();
}
snprintf(result, sizeof(result), "Suite [%s] Test [%s] %s in %lu secs", pSuite->pName, pTest->pName,
pFailure ? "failed" : "passed", (unsigned long)(time(NULL) - test_start_time));
if (pFailure) {
......@@ -202,7 +198,13 @@ static void test_complete_message_handler(const CU_pTest pTest, const CU_pSuite
strncat(result, buffer, strlen(buffer));
}
}
bc_tester_printf(bc_printf_verbosity_info,"%s\n", result);
bc_tester_printf(bc_printf_verbosity_info,"%s", result);
if (test_suite[suite_index]->after_each) {
test_suite[suite_index]->after_each();
}
//insert empty line
bc_tester_printf(bc_printf_verbosity_info,"");
#ifdef __linux
/* use mallinfo() to monitor allocated space. It is linux specific but other methods don't work:
* setrlimit() RLIMIT_DATA doesn't count memory allocated via mmap() (which is used internally by malloc)
......@@ -326,17 +328,20 @@ void bc_tester_helper(const char *name, const char* additionnal_helper) {
}
static int file_exists(const char* root_path) {
int found;
FILE* file;
char * sounds_path = malloc(sizeof(char)*strlen(root_path)+strlen("sounds"));
char * sounds_path = malloc(sizeof(char)*(strlen(root_path)+strlen("sounds")+1));
sprintf(sounds_path, "%ssounds", root_path);
file = fopen(sounds_path, "r");
int found = (file != NULL);
found = (file != NULL);
if (file) fclose(file);
free(sounds_path);
return found;
}
static void detect_res_prefix(const char* prog) {
char* progpath = NULL;
char* progpath = strdup(prog);
char* prefix = NULL;
#if defined(BC_TESTER_WINDOWS_PHONE) || defined(BC_TESTER_WINDOWS_UNIVERSAL)
......@@ -352,10 +357,8 @@ static void detect_res_prefix(const char* prog) {
#endif
if (strchr(prog, '/') != NULL) {
progpath = strdup(prog);
progpath[strrchr(prog, '/') - prog + 1] = '\0';
} else if (strchr(prog, '\\') != NULL) {
progpath = strdup(prog);
progpath[strrchr(prog, '\\') - prog + 1] = '\0';
}
......@@ -367,9 +370,6 @@ static void detect_res_prefix(const char* prog) {
prefix = strdup(progpath);
}
if (progpath != NULL) {
free(progpath);
}
if (prefix != NULL) {
if (bc_tester_resource_dir_prefix == NULL) {
printf("Resource directory set to %s\n", prefix);
......@@ -384,6 +384,10 @@ static void detect_res_prefix(const char* prog) {
printf("Could not find resource directory in %s! Please try again using option --resource-dir and/or --writable-dir.\n", progpath);
abort();
}
if (progpath != NULL) {
free(progpath);
}
}
void bc_tester_init(void (*ftester_printf)(int level, const char *fmt, va_list args), int iverbosity_info, int iverbosity_error) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment