Skip to content

Commit

Permalink
ims_ipsec_pcscf: Fixes for some memory related issues
Browse files Browse the repository at this point in the history
  • Loading branch information
tdimitrov committed Oct 12, 2018
1 parent 4e8104b commit d624042
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/modules/ims_ipsec_pcscf/cmd.c
Expand Up @@ -170,6 +170,10 @@ static int fill_contact(struct pcontact_info* ci, struct sip_msg* m)
ci->via_prot = proto;
ci->aor = cb->contacts->uri;
}
else {
LM_ERR("fill_contact(): Unknown first line type: %d\n", m->first_line.type);
return -1;
}


char* srcip = NULL;
Expand Down
7 changes: 5 additions & 2 deletions src/modules/ims_ipsec_pcscf/ipsec.c
Expand Up @@ -265,8 +265,6 @@ int add_policy(struct mnl_socket* mnl_socket, str src_addr_param, str dest_addr_
char* src_addr = NULL;
char* dest_addr = NULL;

//printf("Adding Policy\n");

memset(l_msg_buf, 0, sizeof(l_msg_buf));
memset(l_tmpls_buf, 0, sizeof(l_tmpls_buf));

Expand Down Expand Up @@ -421,9 +419,14 @@ int remove_policy(struct mnl_socket* mnl_socket, str src_addr_param, str dest_ad
if(mnl_socket_sendto(mnl_socket, &req.n, req.n.nlmsg_len) < 0)
{
LM_ERR("Failed to send Netlink message, error: %s\n", strerror(errno));
pkg_free(src_addr);
pkg_free(dest_addr);
return -1;
}

pkg_free(src_addr);
pkg_free(dest_addr);

return 0;
}

Expand Down
11 changes: 11 additions & 0 deletions src/modules/ims_ipsec_pcscf/spi_list.c
Expand Up @@ -32,6 +32,16 @@ spi_list_t create_list()
return lst;
}

void destroy_list(spi_list_t lst)
{
spi_node_t* l = lst.head;
while(l) {
spi_node_t* n = l->next;
free(l);
l = n;
}
}

int spi_add(spi_list_t* list, uint32_t id)
{
// create new node
Expand Down Expand Up @@ -118,6 +128,7 @@ int spi_remove(spi_list_t* list, uint32_t id)
}

free(t);
return 0;
}

prev = curr;
Expand Down
28 changes: 28 additions & 0 deletions src/modules/ims_ipsec_pcscf/spi_list_tests.c
Expand Up @@ -91,6 +91,8 @@ void case1() // One element list
spi_add(&list, 1);

check(&list, exp, sizeof(exp)/sizeof(int), __func__);

destroy_list(list);
}

void case2() // Two element list
Expand All @@ -103,6 +105,8 @@ void case2() // Two element list
spi_add(&list, 2);

check(&list, exp, sizeof(exp)/sizeof(int), __func__);

destroy_list(list);
}

void case3() // Three element list
Expand All @@ -116,6 +120,8 @@ void case3() // Three element list
spi_add(&list, 3);

check(&list, exp, sizeof(exp)/sizeof(int), __func__);

destroy_list(list);
}

void case4() // Delete head
Expand All @@ -131,6 +137,8 @@ void case4() // Delete head
spi_remove(&list, 1);

check(&list, exp, sizeof(exp)/sizeof(int), __func__);

destroy_list(list);
}


Expand All @@ -147,6 +155,8 @@ void case5() // Delete tail
spi_remove(&list, 3);

check(&list, exp, sizeof(exp)/sizeof(int), __func__);

destroy_list(list);
}

void case6() // Delete between
Expand All @@ -162,6 +172,8 @@ void case6() // Delete between
spi_remove(&list, 2);

check(&list, exp, sizeof(exp)/sizeof(int), __func__);

destroy_list(list);
}

void case7() // Out of order add
Expand All @@ -175,6 +187,8 @@ void case7() // Out of order add
spi_add(&list, 3);

check(&list, exp, sizeof(exp)/sizeof(int), __func__);

destroy_list(list);
}

void case8() //Random operations
Expand All @@ -193,6 +207,8 @@ void case8() //Random operations
spi_remove(&list, 3);

check(&list, exp, sizeof(exp)/sizeof(int), __func__);

destroy_list(list);
}

void case9() // Empty list
Expand All @@ -210,6 +226,8 @@ void case9() // Empty list
spi_remove(&list, 3);

check(&list, exp, sizeof(exp)/sizeof(int), __func__);

destroy_list(list);
}


Expand All @@ -226,6 +244,8 @@ void case10() //No duplicates
spi_add(&list, 3);

check(&list, exp, sizeof(exp)/sizeof(int), __func__);

destroy_list(list);
}

void case11() //No duplicates
Expand All @@ -241,6 +261,8 @@ void case11() //No duplicates
spi_add(&list, 3);

check(&list, exp, sizeof(exp)/sizeof(int), __func__);

destroy_list(list);
}

void case12() //No duplicates
Expand All @@ -255,6 +277,8 @@ void case12() //No duplicates
spi_add(&list, 3);

check(&list, exp, sizeof(exp)/sizeof(int), __func__);

destroy_list(list);
}

void case13() //No duplicates
Expand All @@ -269,6 +293,8 @@ void case13() //No duplicates
spi_add(&list, 1);

check(&list, exp, sizeof(exp)/sizeof(int), __func__);

destroy_list(list);
}

void case14()
Expand All @@ -288,6 +314,8 @@ void case14()
}

printf("%s: OK\n", __func__);

destroy_list(list);
}


Expand Down

0 comments on commit d624042

Please sign in to comment.