Skip to content

Commit 34d5522

Browse files
committed
esl_execute distroys handle->last_ievent internally so we should dup anything for safety before esl_execute
1 parent 4d974bf commit 34d5522

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

icharge.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ int check_account_password(const char *account, const char *password)
1111

1212
void process_event(esl_handle_t *handle, esl_event_t *event)
1313
{
14-
const char *uuid;
14+
const char *uuid = esl_event_get_header(event, "Caller-Unique-ID");
15+
16+
uuid = strdup(uuid);
17+
if (!uuid) abort();
18+
1519
switch (event->event_id) {
1620
case ESL_EVENT_CHANNEL_PARK:
1721
{
@@ -22,7 +26,6 @@ void process_event(esl_handle_t *handle, esl_event_t *event)
2226

2327
if (!service || (service && strcmp(service, "icharge"))) break;
2428

25-
uuid = esl_event_get_header(event, "Caller-Unique-ID");
2629
esl_log(ESL_LOG_INFO, "New Call %s\n", uuid);
2730

2831
esl_execute(handle, "answer", NULL, uuid);
@@ -50,7 +53,6 @@ void process_event(esl_handle_t *handle, esl_event_t *event)
5053
const char *application;
5154
const char *charge_state;
5255

53-
uuid = esl_event_get_header(event, "Caller-Unique-ID");
5456
application = esl_event_get_header(event, "Application");
5557
charge_state = esl_event_get_header(event, "variable_charge_state");
5658

@@ -73,12 +75,13 @@ void process_event(esl_handle_t *handle, esl_event_t *event)
7375
break;
7476
}
7577
case ESL_EVENT_CHANNEL_HANGUP_COMPLETE:
76-
uuid = esl_event_get_header(event, "Caller-Unique-ID");
7778
esl_log(ESL_LOG_INFO, "Hangup %s\n", uuid);
7879
break;
7980
default:
8081
break;
8182
}
83+
84+
free((void *)uuid);
8285
}
8386

8487
int main(void)

0 commit comments

Comments
 (0)