- fixed memleaks
This commit is contained in:
parent
93df94acad
commit
dfa6e086a0
|
@ -473,9 +473,10 @@ static void get_protocols(private_child_proposal_t *this, protocol_id_t ids[2])
|
|||
if (i>1)
|
||||
{
|
||||
/* should not happen, but who knows */
|
||||
return;
|
||||
break;
|
||||
}
|
||||
}
|
||||
iterator->destroy(iterator);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -287,25 +287,22 @@ static status_t destroy(private_sa_config_t *this)
|
|||
|
||||
|
||||
/* delete proposals */
|
||||
while(this->proposals->get_count(this->proposals) > 0)
|
||||
while(this->proposals->remove_last(this->proposals, (void**)&proposal) == SUCCESS)
|
||||
{
|
||||
this->proposals->remove_last(this->proposals, (void**)&proposal);
|
||||
proposal->destroy(proposal);
|
||||
}
|
||||
this->proposals->destroy(this->proposals);
|
||||
|
||||
/* delete traffic selectors */
|
||||
while(this->ts_initiator->get_count(this->ts_initiator) > 0)
|
||||
while(this->ts_initiator->remove_last(this->ts_initiator, (void**)&traffic_selector) == SUCCESS)
|
||||
{
|
||||
this->ts_initiator->remove_last(this->ts_initiator, (void**)&traffic_selector);
|
||||
traffic_selector->destroy(traffic_selector);
|
||||
}
|
||||
this->ts_initiator->destroy(this->ts_initiator);
|
||||
|
||||
/* delete traffic selectors */
|
||||
while(this->ts_responder->get_count(this->ts_responder) > 0)
|
||||
while(this->ts_responder->remove_last(this->ts_responder, (void**)&traffic_selector) == SUCCESS)
|
||||
{
|
||||
this->ts_responder->remove_last(this->ts_responder, (void**)&traffic_selector);
|
||||
traffic_selector->destroy(traffic_selector);
|
||||
}
|
||||
this->ts_responder->destroy(this->ts_responder);
|
||||
|
|
|
@ -558,6 +558,7 @@ sa_payload_t *sa_payload_create_from_child_proposal_list(linked_list_t *proposal
|
|||
iterator->current(iterator, (void**)&proposal);
|
||||
add_child_proposal((private_sa_payload_t*)sa_payload, proposal);
|
||||
}
|
||||
iterator->destroy(iterator);
|
||||
|
||||
return sa_payload;
|
||||
}
|
||||
|
|
|
@ -325,32 +325,42 @@ static status_t process_idr_payload(private_ike_auth_requested_t *this, id_paylo
|
|||
*/
|
||||
static status_t process_sa_payload(private_ike_auth_requested_t *this, sa_payload_t *sa_payload)
|
||||
{
|
||||
child_proposal_t *proposal;
|
||||
child_proposal_t *proposal, *proposal_tmp;
|
||||
linked_list_t *proposal_list;
|
||||
protocol_id_t proto;
|
||||
|
||||
/* TODO fix mem allocation */
|
||||
/* TODO child sa stuff */
|
||||
|
||||
/* get selected proposal */
|
||||
/* get his selected proposal */
|
||||
proposal_list = sa_payload->get_child_proposals(sa_payload);
|
||||
/* check count of proposals */
|
||||
if (proposal_list->get_count(proposal_list) == 0)
|
||||
{
|
||||
/* no proposal? we accept this, no child sa is built */
|
||||
/* no proposal? we accept this, but no child sa is built */
|
||||
this->logger->log(this->logger, AUDIT, "IKE_AUTH reply's SA_PAYLOAD didn't contain any proposals. No CHILD_SA created",
|
||||
proposal_list->get_count(proposal_list));
|
||||
proposal_list->destroy(proposal_list);
|
||||
return SUCCESS;
|
||||
}
|
||||
if (proposal_list->get_count(proposal_list) > 1)
|
||||
{
|
||||
this->logger->log(this->logger, AUDIT, "IKE_AUTH reply's SA_PAYLOAD contained %d proposal. Deleting IKE_SA",
|
||||
proposal_list->get_count(proposal_list));
|
||||
while (proposal_list->remove_last(proposal_list, (void**)&proposal) == SUCCESS)
|
||||
{
|
||||
proposal->destroy(proposal);
|
||||
}
|
||||
proposal_list->destroy(proposal_list);
|
||||
return DELETE_ME;
|
||||
}
|
||||
|
||||
/* we have to re-check here if other's selection is valid */
|
||||
proposal = this->sa_config->select_proposal(this->sa_config, proposal_list);
|
||||
/* list not needed anymore */
|
||||
while (proposal_list->remove_last(proposal_list, (void**)&proposal_tmp) == SUCCESS)
|
||||
{
|
||||
proposal_tmp->destroy(proposal_tmp);
|
||||
}
|
||||
proposal_list->destroy(proposal_list);
|
||||
/* got a match? */
|
||||
if (proposal == NULL)
|
||||
{
|
||||
this->logger->log(this->logger, AUDIT, "IKE_AUTH reply contained a not offered proposal. Deleting IKE_SA");
|
||||
|
@ -376,6 +386,9 @@ static status_t process_sa_payload(private_ike_auth_requested_t *this, sa_payloa
|
|||
}
|
||||
}
|
||||
|
||||
/* TODO: Proposal? child_sa */
|
||||
proposal->destroy(proposal);
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
@ -525,10 +525,11 @@ static status_t build_sa_payload (private_ike_sa_init_requested_t *this, message
|
|||
sa_payload_t *sa_payload;
|
||||
sa_config_t *sa_config;
|
||||
|
||||
/* get proposals form config, add to payload */
|
||||
sa_config = this->ike_sa->get_sa_config(this->ike_sa);
|
||||
proposal_list = sa_config->get_proposals(sa_config);
|
||||
sa_payload = sa_payload_create_from_child_proposal_list(proposal_list);
|
||||
/* TODO: fix mem allocation */
|
||||
|
||||
/* TODO child sa stuff */
|
||||
|
||||
this->logger->log(this->logger, CONTROL|LEVEL2, "Add SA payload to message");
|
||||
|
|
|
@ -386,12 +386,11 @@ static status_t build_idr_payload(private_ike_sa_init_responded_t *this, id_payl
|
|||
*/
|
||||
static status_t build_sa_payload(private_ike_sa_init_responded_t *this, sa_payload_t *request, message_t *response)
|
||||
{
|
||||
child_proposal_t *proposal;
|
||||
child_proposal_t *proposal, *proposal_tmp;
|
||||
linked_list_t *proposal_list;
|
||||
sa_payload_t *sa_response;
|
||||
protocol_id_t proto;
|
||||
|
||||
/* TODO: fix mem */
|
||||
/* TODO: child sa stuff */
|
||||
|
||||
/* get proposals from request */
|
||||
|
@ -402,12 +401,20 @@ static status_t build_sa_payload(private_ike_sa_init_responded_t *this, sa_paylo
|
|||
this->logger->log(this->logger, AUDIT, "IKE_AUH request did not contain any proposals. No CHILD_SA created");
|
||||
sa_response = sa_payload_create();
|
||||
response->add_payload(response, (payload_t*)sa_response);
|
||||
proposal_list->destroy(proposal_list);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
/* now select a proposal */
|
||||
this->logger->log(this->logger, CONTROL|LEVEL1, "Selecting proposals:");
|
||||
proposal = this->sa_config->select_proposal(this->sa_config, proposal_list);
|
||||
/* list is not needed anymore */
|
||||
while (proposal_list->remove_last(proposal_list, (void**)&proposal_tmp) == SUCCESS)
|
||||
{
|
||||
proposal_tmp->destroy(proposal_tmp);
|
||||
}
|
||||
proposal_list->destroy(proposal_list);
|
||||
/* do we have a proposal */
|
||||
if (proposal == NULL)
|
||||
{
|
||||
this->logger->log(this->logger, AUDIT, "IKE_AUTH request did not contain any proposals we accept. Deleting IKE_SA");
|
||||
|
@ -436,6 +443,7 @@ static status_t build_sa_payload(private_ike_sa_init_responded_t *this, sa_paylo
|
|||
/* create payload with selected propsal */
|
||||
sa_response = sa_payload_create_from_child_proposal(proposal);
|
||||
response->add_payload(response, (payload_t*)sa_response);
|
||||
proposal->destroy(proposal);
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
|
|
@ -43,6 +43,19 @@ typedef struct iterator_t iterator_t;
|
|||
*/
|
||||
struct iterator_t {
|
||||
|
||||
/**
|
||||
* @brief Iterate over all items.
|
||||
*
|
||||
* The easy way to iterate over items.
|
||||
*
|
||||
* @param this calling object
|
||||
* @param[out] value item
|
||||
* @return
|
||||
* - TRUE, if more elements are avaiable,
|
||||
* - FALSE otherwise
|
||||
*/
|
||||
bool (*iterate) (iterator_t *this, void** value);
|
||||
|
||||
/**
|
||||
* @brief Moves to the next element, if available.
|
||||
*
|
||||
|
|
|
@ -156,7 +156,42 @@ struct private_iterator_t {
|
|||
/**
|
||||
* Implementation of iterator_t.has_next.
|
||||
*/
|
||||
bool iterator_has_next(private_iterator_t *this)
|
||||
static bool iterate(private_iterator_t *this, void** value)
|
||||
{
|
||||
if (this->list->count == 0)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
if (this->current == NULL)
|
||||
{
|
||||
this->current = (this->forward) ? this->list->first : this->list->last;
|
||||
*value = this->current->value;
|
||||
return TRUE;
|
||||
}
|
||||
if (this->forward)
|
||||
{
|
||||
if (this->current->next == NULL)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
this->current = this->current->next;
|
||||
*value = this->current->value;
|
||||
return TRUE;
|
||||
}
|
||||
/* backward */
|
||||
if (this->current->previous == NULL)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
this->current = this->current->previous;
|
||||
*value = this->current->value;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of iterator_t.has_next.
|
||||
*/
|
||||
static bool iterator_has_next(private_iterator_t *this)
|
||||
{
|
||||
if (this->list->count == 0)
|
||||
{
|
||||
|
@ -632,6 +667,7 @@ static iterator_t *create_iterator (private_linked_list_t *linked_list,bool forw
|
|||
{
|
||||
private_iterator_t *this = allocator_alloc_thing(private_iterator_t);
|
||||
|
||||
this->public.iterate = (bool (*) (iterator_t *this, void **value)) iterate;
|
||||
this->public.has_next = (bool (*) (iterator_t *this)) iterator_has_next;
|
||||
this->public.current = (status_t (*) (iterator_t *this, void **value)) iterator_current;
|
||||
this->public.insert_before = (void (*) (iterator_t *this, void *item)) insert_before;
|
||||
|
|
Loading…
Reference in New Issue