Fix incorrect deletion code.

This commit is contained in:
Danila Fedorin 2018-02-08 18:40:56 -08:00
parent e849cc8ba2
commit eecfe653e3
1 changed files with 8 additions and 6 deletions

View File

@ -50,16 +50,18 @@ liblex_result _eval_config_free_state(eval_state* state) {
liblex_result eval_config_remove(eval_config* config, const char* pattern, int pattern_id) {
liblex_result result = LIBLEX_SUCCESS;
ll_node** head = &(config->states.head);
while(*head && result == LIBLEX_SUCCESS) {
eval_state* current_state = (*head)->data;
ll_node* head = config->states.head;
while(head && result == LIBLEX_SUCCESS) {
eval_state* current_state = head->data;
if(strcmp(current_state->source, pattern) == 0 && current_state->pattern->head->pattern_id == pattern_id) {
ll_node* to_delete = *head;
(*head) = (*head)->next;
ll_node* to_delete = head;
head = head->next;
*(to_delete->prev ? &to_delete->prev->next : &(config->states.head)) = to_delete->next;
*(to_delete->next ? &to_delete->next->prev : &(config->states.tail)) = to_delete->prev;
free(to_delete);
result = _eval_config_free_state(current_state);
} else {
head = &((*head)->next);
head = head->next;
}
}
return result;