}
this_ptr->cl_data = (unsigned char*)realloc(this_ptr->cl_data, this_ptr->cl_data_size + len + 1);
- memcpy(&(this_ptr->cl_data[this_ptr->cl_data_size]), (char*)in, len);
- this_ptr->cl_data_size += len;
- this_ptr->cl_data[this_ptr->cl_data_size] = '\0';
- this_ptr->connectionHandler->resetLastPingReceived();
+
+ if (this_ptr->cl_data) {
+ memcpy(&(this_ptr->cl_data[this_ptr->cl_data_size]), (char*)in, len);
+ this_ptr->cl_data_size += len;
+ this_ptr->cl_data[this_ptr->cl_data_size] = '\0';
+ this_ptr->connectionHandler->resetLastPingReceived();
+ }
if (lws_remaining_packet_payload(wsi) == 0) {
- this_ptr->json_parse((char*)this_ptr->cl_data);
+ if (this_ptr->cl_data) {
+ this_ptr->json_parse((char*)this_ptr->cl_data);
+ }
if (this_ptr->eventType == CONNECT_EVENT) {
this_ptr->handleConnectMessage(this_ptr->UID);
int payload_size) {
int l = 0;
int header_size = 0;
+ int data_len = 0;
+
+ if (data) {
+ data_len = strlen(data);
+ } else {
+ data_len = 0;
+ }
- int prepare_buf_size = LWS_SEND_BUFFER_PRE_PADDING + strlen(data) + payload_size + 512 + LWS_SEND_BUFFER_POST_PADDING;
+ int prepare_buf_size = LWS_SEND_BUFFER_PRE_PADDING + data_len + payload_size + 512 + LWS_SEND_BUFFER_POST_PADDING;
unsigned char *prepare_buf = new unsigned char[prepare_buf_size];
if (payload) {