static int Client_read(client_t *client);
static int Client_write(client_t *client);
static int Client_send_udp(client_t *client, uint8_t *data, int len);
static int Client_read(client_t *client);
static int Client_write(client_t *client);
static int Client_send_udp(client_t *client, uint8_t *data, int len);
init_list_entry(&cd->node);
cd->codec = codec;
list_add_tail(&cd->node, &client->codecs);
init_list_entry(&cd->node);
cd->codec = codec;
list_add_tail(&cd->node, &client->codecs);
init_list_entry(&token->node);
token->token = strdup(token_string);
if (token->token == NULL)
init_list_entry(&token->node);
token->token = strdup(token_string);
if (token->token == NULL)
- cd = malloc(sizeof(codec_t));
- if (!cd)
- Log_fatal("Out of memory");
- memset(cd, 0, sizeof(codec_t));
+ cd = Memory_safeCalloc(1, sizeof(codec_t));
- if ((newclient = calloc(1, sizeof(client_t))) == NULL)
- Log_fatal("(%s:%s): Out of memory while allocating %d bytes.", __FILE__, __LINE__, sizeof(client_t));
+ newclient = Memory_safeCalloc(1, sizeof(client_t));
newclient->tcpfd = fd;
memcpy(&newclient->remote_tcp, remote, sizeof(struct sockaddr_storage));
newclient->ssl = SSLi_newconnection(&newclient->tcpfd, &newclient->SSLready);
if (newclient->ssl == NULL) {
newclient->tcpfd = fd;
memcpy(&newclient->remote_tcp, remote, sizeof(struct sockaddr_storage));
newclient->ssl = SSLi_newconnection(&newclient->tcpfd, &newclient->SSLready);
if (newclient->ssl == NULL) {
- Log_warn("SSL negotiation failed with %s on port %d", Util_addressToString(remote), Util_addressToPort(remote));
+ addressString = Util_addressToString(remote);
+ Log_warn("SSL negotiation failed with %s on port %d", addressString, Util_addressToPort(remote));
+ free(addressString);
- if (client->release)
- free(client->release);
- if (client->os)
- free(client->os);
- if (client->os_version)
- free(client->os_version);
- if (client->username)
- free(client->username);
- if (client->context)
- free(client->context);
+
+ free(client->release);
+ free(client->os);
+ free(client->os_version);
+ free(client->username);
+ free(client->context);
- if (fd == list_get_entry(itr, client_t, node)->tcpfd) {
- client = list_get_entry(itr, client_t, node);
- break;
+ client_t *client = list_get_entry(itr, client_t, node);
+
+ if (client->tcpfd == fd) {
+ return client;
- list_iterate(itr, &clients) {
- if(fd == list_get_entry(itr, client_t, node)->tcpfd) {
- client = list_get_entry(itr, client_t, node);
- break;
- }
- }
- message = malloc(strlen(text) + 1);
- if (!message)
- Log_fatal("Out of memory");
- tree_id = malloc(sizeof(uint32_t));
- if (!tree_id)
- Log_fatal("Out of memory");
+ message = Memory_safeMalloc(1, strlen(text) + 1);
+ tree_id = Memory_safeMalloc(1, sizeof(uint32_t));
Log_debug("Msg %d to %s refcount %d", msg->messageType, itr->username, msg->refcount);
Client_send_message(itr, msg);
}
}
Log_debug("Msg %d to %s refcount %d", msg->messageType, itr->username, msg->refcount);
Client_send_message(itr, msg);
}
}
- Msg_free(msg); /* Free our reference to the message */
-
- if (count == 0)
- Msg_free(msg); /* If only 1 client is connected then no message is passed
- * to Client_send_message(). Free it here. */
+ Msg_free(msg); /* Consume caller's reference. */
Log_debug("Msg %d to %s refcount %d", msg->messageType, itr->username, msg->refcount);
Client_send_message_ver(itr, msg, version);
}
}
Log_debug("Msg %d to %s refcount %d", msg->messageType, itr->username, msg->refcount);
Client_send_message_ver(itr, msg, version);
}
}
- Msg_free(msg); /* Free our reference to the message */
-
- if (count == 0)
- Msg_free(msg); /* If only 1 client is connected then no message is passed
- * to Client_send_message(). Free it here. */
+ Msg_free(msg); /* Consume caller's reference. */
if (memcmp(itraddress, fromaddress, addresslength) == 0) {
if (checkDecrypt(itr, encrypted, buffer, len)) {
memcpy(itr->key, key, KEY_LENGTH);
if (memcmp(itraddress, fromaddress, addresslength) == 0) {
if (checkDecrypt(itr, encrypted, buffer, len)) {
memcpy(itr->key, key, KEY_LENGTH);
- Log_info_client(itr, "New UDP connection from %s on port %d", Util_clientAddressToString(itr), fromport);
+ char* clientAddressString = Util_clientAddressToString(itr);
+ Log_info_client(itr, "New UDP connection from %s on port %d", clientAddressString, fromport);
+ free(clientAddressString);
- Log_debug("Unknown UDP message type from %s port %d", Util_clientAddressToString(itr), fromport);
+ clientAddressString = Util_clientAddressToString(itr);
+ Log_debug("Unknown UDP message type from %s port %d", clientAddressString, fromport);
+ free(clientAddressString);
if (vt->channels[i].linked && !list_empty(&ch->channel_links)) {
struct dlist *ch_itr;
list_iterate(ch_itr, &ch->channel_links) {
if (vt->channels[i].linked && !list_empty(&ch->channel_links)) {
struct dlist *ch_itr;
list_iterate(ch_itr, &ch->channel_links) {
list_iterate(itr, &ch_link->clients) {
client_t *c;
c = list_get_entry(itr, client_t, chan_node);
list_iterate(itr, &ch_link->clients) {
client_t *c;
c = list_get_entry(itr, client_t, chan_node);
CryptState_encrypt(&client->cryptState, data, buf, len);
#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
CryptState_encrypt(&client->cryptState, data, buf, len);
#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__APPLE__)