-
Notifications
You must be signed in to change notification settings - Fork 1
/
0001-switch-console-crash.patch
61 lines (57 loc) · 1.72 KB
/
0001-switch-console-crash.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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;