Skip to content

Commit

Permalink
Create 0001-switch-console-crash.patch
Browse files Browse the repository at this point in the history
  • Loading branch information
lazedo authored Jan 25, 2018
1 parent edef5c9 commit f5fc727
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions 0001-switch-console-crash.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
diff --git a/src/switch_console.c b/src/switch_console.c
index 876b774..048a3cf 100644
--- a/src/switch_console.c
+++ b/src/switch_console.c
@@ -150,8 +150,6 @@
SWITCH_DECLARE_NONSTD(switch_status_t) switch_console_stream_write(switch_stream_handle_t *handle, const char *fmt, ...)
{
va_list ap;
- char *buf = handle->data;
- char *end = handle->end;
int ret = 0;
char *data = NULL;

@@ -160,44 +158,16 @@
}

va_start(ap, fmt);
- //ret = switch_vasprintf(&data, fmt, ap);
if (!(data = switch_vmprintf(fmt, ap))) {
ret = -1;
}
va_end(ap);

if (data) {
- switch_size_t remaining = handle->data_size - handle->data_len;
- switch_size_t need = strlen(data) + 1;
-
- if ((remaining < need) && handle->alloc_len) {
- switch_size_t new_len;
- void *new_data;
-
- new_len = handle->data_size + need + handle->alloc_chunk;
- if ((new_data = realloc(handle->data, new_len))) {
- handle->data_size = handle->alloc_len = new_len;
- handle->data = new_data;
- buf = handle->data;
- remaining = handle->data_size - handle->data_len;
- handle->end = (uint8_t *) (handle->data) + handle->data_len;
- end = handle->end;
- } else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
- free(data);
- return SWITCH_STATUS_FALSE;
- }
- }
-
- if (remaining < need) {
- ret = -1;
- } else {
- ret = 0;
- switch_snprintf(end, remaining, "%s", data);
- handle->data_len = strlen(buf);
- handle->end = (uint8_t *) (handle->data) + handle->data_len;
- }
+ switch_size_t datalen = strlen(data);
+ switch_status_t res = switch_console_stream_raw_write(handle, (uint8_t *)data, datalen);
free(data);
+ return res;
}

return ret ? SWITCH_STATUS_FALSE : SWITCH_STATUS_SUCCESS;

0 comments on commit f5fc727

Please sign in to comment.