Replace sys_signame with strsignal and rename malloc functions

This commit is contained in:
Shuanglei Tao
2016-12-24 21:59:57 +08:00
parent c8975442ad
commit 70cb376208
4 changed files with 33 additions and 63 deletions

View File

@@ -60,7 +60,7 @@ parse_window_size(const char *json) {
rows = json_object_get_int(o);
json_object_put(obj);
struct winsize *size = t_malloc(sizeof(struct winsize));
struct winsize *size = xmalloc(sizeof(struct winsize));
memset(size, 0, sizeof(struct winsize));
size->ws_col = (unsigned short) columns;
size->ws_row = (unsigned short) rows;
@@ -112,7 +112,7 @@ tty_client_destroy(struct tty_client *client) {
// free the buffer
if (client->buffer != NULL)
t_free(client->buffer);
free(client->buffer);
// remove from clients list
pthread_mutex_lock(&server->lock);
@@ -162,10 +162,10 @@ thread_run_command(void *args) {
if (FD_ISSET (pty, &des_set)) {
memset(buf, 0, BUF_SIZE);
bytes = (int) read(pty, buf, BUF_SIZE);
struct pty_data *frame = (struct pty_data *) t_malloc(sizeof(struct pty_data));
struct pty_data *frame = (struct pty_data *) xmalloc(sizeof(struct pty_data));
frame->len = bytes;
if (bytes > 0) {
frame->data = t_malloc((size_t) bytes);
frame->data = xmalloc((size_t) bytes);
memcpy(frame->data, buf, bytes);
}
pthread_mutex_lock(&client->lock);
@@ -234,7 +234,7 @@ callback_tty(struct lws *wsi, enum lws_callback_reasons reason,
// read error or client exited, close connection
if (frame->len <= 0) {
STAILQ_REMOVE_HEAD(&client->queue, list);
t_free(frame);
free(frame);
return -1;
}
@@ -244,7 +244,7 @@ callback_tty(struct lws *wsi, enum lws_callback_reasons reason,
unsigned char *p = &message[LWS_PRE];
size_t n = sprintf((char *) p, "%c%s", OUTPUT, b64_text);
t_free(b64_text);
free(b64_text);
if (lws_write(wsi, p, n, LWS_WRITE_TEXT) < n) {
lwsl_err("lws_write\n");
@@ -252,8 +252,8 @@ callback_tty(struct lws *wsi, enum lws_callback_reasons reason,
}
STAILQ_REMOVE_HEAD(&client->queue, list);
t_free(frame->data);
t_free(frame);
free(frame->data);
free(frame);
if (lws_partial_buffered(wsi)) {
lws_callback_on_writable(wsi);
@@ -265,11 +265,11 @@ callback_tty(struct lws *wsi, enum lws_callback_reasons reason,
case LWS_CALLBACK_RECEIVE:
if (client->buffer == NULL) {
client->buffer = t_malloc(len + 1);
client->buffer = xmalloc(len + 1);
client->len = len;
memcpy(client->buffer, in, len);
} else {
client->buffer = t_realloc(client->buffer, client->len + len + 1);
client->buffer = xrealloc(client->buffer, client->len + len + 1);
memcpy(client->buffer + client->len, in, len);
client->len += len;
}
@@ -312,7 +312,7 @@ callback_tty(struct lws *wsi, enum lws_callback_reasons reason,
if (ioctl(client->pty, TIOCSWINSZ, size) == -1) {
lwsl_err("ioctl TIOCSWINSZ: %d (%s)\n", errno, strerror(errno));
}
t_free(size);
free(size);
}
break;
case JSON_DATA:
@@ -337,7 +337,7 @@ callback_tty(struct lws *wsi, enum lws_callback_reasons reason,
}
if (client->buffer != NULL) {
t_free(client->buffer);
free(client->buffer);
client->buffer = NULL;
}
break;