Commit 700ad5a8 authored by Simon Morlat's avatar Simon Morlat

fix many memory leaks

parent 1e126c1a
......@@ -128,7 +128,7 @@ static void belle_sip_header_destroy(belle_sip_header_t *header){
void belle_sip_header_set_next(belle_sip_header_t* header,belle_sip_header_t* next) {
if (next) belle_sip_object_ref(next);
if(header->next) belle_sip_object_unref(header->next);
if (header->next) belle_sip_object_unref(header->next);
header->next = next;
}
......@@ -188,6 +188,7 @@ static void belle_sip_header_address_init(belle_sip_header_address_t* object){
static void belle_sip_header_address_destroy(belle_sip_header_address_t* address) {
if (address->displayname) belle_sip_free(address->displayname);
if (address->uri) belle_sip_object_unref(address->uri);
if (address->absolute_uri) belle_sip_object_unref(address->absolute_uri);
}
static void belle_sip_header_address_clone(belle_sip_header_address_t *addr, const belle_sip_header_address_t *orig){
......
......@@ -129,6 +129,7 @@ static void belle_sip_provider_dispatch_request(belle_sip_provider_t* prov, bell
return;
}
}
if (prov->unconditional_answer_enabled && strcmp("ACK",method)!=0) { /*always answer 480 in this case*/
belle_sip_server_transaction_t *tr=belle_sip_provider_create_server_transaction(prov,req);
belle_sip_server_transaction_send_response(tr,belle_sip_response_create_from_request(req,480));
......
......@@ -95,6 +95,7 @@ static void test_file_path(void) {
/*this is INVALID*/
source_uri = belle_generic_uri_parse("file://./relative-file");
BC_ASSERT_PTR_NOT_NULL(source_uri);
if (source_uri) belle_sip_object_unref(source_uri);
/* PATH segment always start by / */
source_uri = belle_generic_uri_parse("./relative-file");
......
......@@ -336,5 +336,5 @@ test_t http_tests[] = {
{ "http GET with long user body", http_get_long_user_body}
};
test_suite_t http_test_suite = {"http", http_before_all, http_after_all, belle_sip_tester_before_each,
belle_sip_tester_after_each, sizeof(http_tests) / sizeof(http_tests[0]), http_tests};
test_suite_t http_test_suite = {"http", http_before_all, http_after_all, NULL,
NULL, sizeof(http_tests) / sizeof(http_tests[0]), http_tests};
......@@ -70,18 +70,19 @@ static void test_complex_contact_header(void) {
l_next = belle_sip_header_get_next(BELLE_SIP_HEADER(L_contact));
L_next_contact = BELLE_SIP_HEADER_CONTACT(l_next);
BC_ASSERT_PTR_NOT_NULL(L_next_contact);
BC_ASSERT_PTR_NOT_NULL( belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(L_contact)));
BC_ASSERT_PTR_NOT_NULL( belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(L_next_contact)));
belle_sip_object_unref(BELLE_SIP_OBJECT(L_contact));
L_contact = belle_sip_header_contact_parse("Contact: super toto <sip:titi.com>;expires=3600; q=0.7");
l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_contact));
belle_sip_object_unref(BELLE_SIP_OBJECT(L_contact));
L_contact = belle_sip_header_contact_parse(l_raw_header);
belle_sip_free(l_raw_header);
BC_ASSERT_STRING_EQUAL(belle_sip_header_address_get_displayname((belle_sip_header_address_t*)L_contact), "super toto");
belle_sip_object_unref(BELLE_SIP_OBJECT(L_contact));
BC_ASSERT_PTR_NULL(belle_sip_header_contact_parse("m:sip:titi.com, nimportequoi"));
}
......@@ -390,6 +391,7 @@ static void test_route_header(void) {
char* l_raw_header;
BC_ASSERT_PTR_NOT_NULL_FATAL(address);
L_route = belle_sip_header_route_create(address);
belle_sip_object_unref(address);
BC_ASSERT_PTR_NOT_NULL_FATAL(L_route);
l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_route));
belle_sip_object_unref(BELLE_SIP_OBJECT(L_route));
......@@ -814,6 +816,7 @@ static void test_subscription_state_header(void) {
static void test_refer_to_header(void) {
belle_sip_uri_t* L_uri;
belle_sip_header_address_t *ha;
belle_sip_header_refer_to_t* L_refer_to = belle_sip_header_refer_to_parse("Refer-To: <sip:dave@denver.example.org?Replaces=12345%40192.168.118.3%3Bto-tag%3D12345%3Bfrom-tag%3D5FFE-3994>");
char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_refer_to));
belle_sip_object_unref(BELLE_SIP_OBJECT(L_refer_to));
......@@ -826,7 +829,8 @@ static void test_refer_to_header(void) {
BC_ASSERT_STRING_EQUAL(belle_sip_uri_get_host(L_uri), "denver.example.org");
belle_sip_object_unref(BELLE_SIP_OBJECT(L_refer_to));
/*test factory*/
L_refer_to = belle_sip_header_refer_to_create(belle_sip_header_address_parse("\"super man\" <sip:titi.com>"));
L_refer_to = belle_sip_header_refer_to_create((ha=belle_sip_header_address_parse("\"super man\" <sip:titi.com>")));
belle_sip_object_unref(ha);
BC_ASSERT_PTR_NOT_NULL_FATAL(L_refer_to);
L_uri = belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(L_refer_to));
BC_ASSERT_PTR_NOT_NULL_FATAL(L_uri);
......@@ -878,6 +882,7 @@ static void test_replaces_escaped_header(void) {
L_replaces=belle_sip_header_replaces_create2(escaped_to_string);
l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_replaces));
belle_sip_object_unref(BELLE_SIP_OBJECT(L_replaces));
belle_sip_object_unref(L_tmp);
L_tmp= belle_sip_header_replaces_parse(l_raw_header);
L_replaces = BELLE_SIP_HEADER_REPLACES(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp)));
belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp));
......@@ -899,13 +904,19 @@ static void _test_date_header(void){
#define DATE_UTC_EXAMPLE 1014296523L /* the above date in UTC */
date=belle_sip_header_date_parse("Date: " DATE_EXAMPLE);
BC_ASSERT_PTR_NOT_NULL(date);
utc=belle_sip_header_date_get_time(date);
BC_ASSERT_EQUAL(utc,DATE_UTC_EXAMPLE,int,"%d");
if (date){
utc=belle_sip_header_date_get_time(date);
BC_ASSERT_EQUAL(utc,DATE_UTC_EXAMPLE,int,"%d");
belle_sip_object_unref(date);
}
date2=belle_sip_header_date_create_from_time(&utc);
BC_ASSERT_PTR_NOT_NULL(date2);
BC_ASSERT_TRUE(strcmp(belle_sip_header_date_get_date(date2),DATE_EXAMPLE)==0);
BC_ASSERT_PTR_NULL(belle_sip_header_date_parse("nimportequoi"));
if (date2){
BC_ASSERT_TRUE(strcmp(belle_sip_header_date_get_date(date2),DATE_EXAMPLE)==0);
BC_ASSERT_PTR_NULL(belle_sip_header_date_parse("nimportequoi"));
belle_sip_object_unref(date2);
}
}
#endif
......
......@@ -285,6 +285,7 @@ static void test_extract_source(void) {
BC_ASSERT_EQUAL(belle_sip_uri_get_port(source),0,int,"%d");
BC_ASSERT_STRING_EQUAL(belle_sip_uri_get_transport_param(source),"tcp");
belle_sip_object_unref(message);
belle_sip_object_unref(source);
message = belle_sip_message_parse(invite_2);
request = BELLE_SIP_REQUEST(message);
......@@ -294,7 +295,7 @@ static void test_extract_source(void) {
BC_ASSERT_EQUAL(belle_sip_uri_get_port(source),15060,int,"%d");
BC_ASSERT_STRING_EQUAL(belle_sip_uri_get_transport_param(source),"udp");
belle_sip_object_unref(message);
belle_sip_object_unref(source);
}
static void test_sipfrag(void) {
......@@ -330,6 +331,7 @@ const char * raw_message= "INVITE sip:jehan@81.56.113.2:50343;transport=tcp;line
belle_sip_message_t* message = belle_sip_message_parse(raw_message);
BC_ASSERT_FALSE(belle_sip_message_check_headers(message));
belle_sip_object_unref(message);
}
static void testMalformedOptionnalHeaderInMessage(void) {
......@@ -424,8 +426,8 @@ void channel_parser_tester_recovery_from_error_base (const char* prelude,const c
BC_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(message,"Proxy-Authorization"));
check_uri_and_headers(message);
belle_sip_object_unref(BELLE_SIP_OBJECT(message));
belle_sip_object_unref(channel);
belle_sip_object_unref(message);
belle_sip_object_unref(stack);
}
......@@ -765,6 +767,8 @@ static void testUriHeadersInInvite(void) {
belle_sip_object_unref(request);
belle_sip_object_unref(prov);
belle_sip_object_unref(stack);
}
static void testUrisComponentsForRequest(void) {
......@@ -785,6 +789,8 @@ static void testUrisComponentsForRequest(void) {
BC_ASSERT_PTR_NOT_NULL(request);
t=belle_sip_provider_create_client_transaction(prov,request);
BC_ASSERT_NOT_EQUAL(belle_sip_client_transaction_send_request(t),0,int,"%d");
belle_sip_object_unref(prov);
belle_sip_object_unref(stack);
}
static void testGenericMessage(void) {
......@@ -940,6 +946,7 @@ void channel_parser_http_response(void) {
BC_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(message,"Vary"));
belle_sip_object_unref(BELLE_SIP_OBJECT(message));
belle_sip_object_unref(channel);
belle_sip_object_unref(stack);
}
......@@ -1001,6 +1008,8 @@ void testGetBody(void) {
BC_ASSERT_EQUAL(belle_sip_header_content_length_get_content_length(ctlt),strlen(belle_sip_message_get_body(message)),int,"%d");
BC_ASSERT_EQUAL(belle_sip_header_content_length_get_content_length(ctlt),belle_sip_message_get_body_size(message),int,"%d");
belle_sip_object_unref(message);
belle_sip_object_unref(channel);
belle_sip_object_unref(stack);
}
/* NOTE - ORDER IS IMPORTANT - MUST TEST fread() AFTER fprintf() */
......
......@@ -728,6 +728,6 @@ test_t register_tests[] = {
{ "Nonce reutilization", reuse_nonce }
};
test_suite_t register_test_suite = {"REGISTER", register_before_all, register_after_all, belle_sip_tester_before_each,
belle_sip_tester_after_each, sizeof(register_tests) / sizeof(register_tests[0]),
test_suite_t register_test_suite = {"REGISTER", register_before_all, register_after_all, NULL,
NULL, sizeof(register_tests) / sizeof(register_tests[0]),
register_tests};
......@@ -199,7 +199,7 @@ void belle_sip_tester_after_each() {
int leaked_objects = belle_sip_object_get_object_count() - leaked_objects_count;
if (leaked_objects > 0) {
belle_sip_object_dump_active_objects();
belle_sip_fatal("%d objects were leaked in latest test, please fix that!\n", leaked_objects);
belle_sip_error("%d objects were leaked in latest test, please fix that!\n", leaked_objects);
}
}
......
......@@ -449,9 +449,8 @@ static belle_sip_header_address_t* test_header_address_parsing(const char* addre
}
static void test_empty_password(void){
static const char *address_fail = "sip:France:@+123456789";
static const char *address_valid = "sip:France:@toto";
const char *address_fail = "sip:France:@+123456789";
const char *address_valid = "sip:France:@toto";
const char* passwd;
belle_sip_header_address_t* headerAddr;
belle_sip_uri_t* uri;
......@@ -467,6 +466,8 @@ static void test_empty_password(void){
passwd = belle_sip_uri_get_user_password(uri);
BC_ASSERT_PTR_EQUAL(passwd, NULL);
if (headerAddr) belle_sip_object_unref(headerAddr);
}
......
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