[Core] Fix switch_event_base_add_header leaking memory when headers are with indexes. Add a unit-test.

* [Unit-tests] Add a test provoking switch_event_add_header to memory leak.
* [Core] Fix switch_event_base_add_header leaking memory when headers are with indexes.
This commit is contained in:
Andrey Volk 2021-11-03 17:00:08 +03:00
parent 3c6ffc146f
commit 0fdd5b6727
3 changed files with 22 additions and 0 deletions

View File

@ -484,11 +484,14 @@ static esl_status_t esl_event_base_add_header(esl_event_t *event, esl_stack_t st
exists = 1;
}
FREE(data);
goto redraw;
}
} else if (tmp_header) {
free_header(&tmp_header);
}
FREE(data);
goto end;
} else {
if ((stack & ESL_STACK_PUSH) || (stack & ESL_STACK_UNSHIFT)) {

View File

@ -1062,11 +1062,14 @@ static switch_status_t switch_event_base_add_header(switch_event_t *event, switc
exists = 1;
}
FREE(data);
goto redraw;
}
} else if (tmp_header) {
free_header(&tmp_header);
}
FREE(data);
goto end;
} else {
if ((stack & SWITCH_STACK_PUSH) || (stack & SWITCH_STACK_UNSHIFT)) {

View File

@ -51,6 +51,22 @@ FST_CORE_BEGIN("./conf")
}
FST_TEARDOWN_END()
FST_TEST_BEGIN(test_switch_event_add_header_leak)
{
switch_event_t* event;
if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_CALLSTATE) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Channel-Call-State-Number[0]", "1");
switch_event_fire(&event);
}
if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_CALLSTATE) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Channel-Call-State-Number[5000]", "12");
switch_event_fire(&event);
}
}
FST_TEST_END()
FST_TEST_BEGIN(test_xml_free_attr)
{
switch_xml_t parent_xml = switch_xml_new("xml");