This is more efficient than the combination of malloc(), strlen() and
strcpy() that we used before.
uint32_t *tree_id;
message_t *sendmsg = NULL;
- message = Memory_safeMalloc(1, strlen(text) + 1);
+ message = strdup(text);
+
+ if (message == NULL)
+ Log_fatal("Out of memory");
+
tree_id = Memory_safeMalloc(1, sizeof(uint32_t));
*tree_id = 0;
sendmsg = Msg_create(TextMessage);
sendmsg->payload.textMessage->message = message;
sendmsg->payload.textMessage->n_tree_id = 1;
sendmsg->payload.textMessage->tree_id = tree_id;
- strcpy(message, text);
+
Client_send_message(client, sendmsg);
}