#include <stdlib.h>
#include "log.h"
+#include "memory.h"
#include "list.h"
#include "client.h"
#include "messages.h"
sendmsg->payload.channelState->channel_id = ch_itr->id;
sendmsg->payload.channelState->n_links = ch_itr->linkcount;
- links = (uint32_t *)malloc(ch_itr->linkcount * sizeof(uint32_t));
+ links = (uint32_t*)Memory_safeMalloc(
+ ch_itr->linkcount,
+ sizeof(uint32_t));
list_iterate(itr, &ch_itr->channel_links) { /* Iterate links */
+ channellist_t *chl;
channel_t *ch;
- ch = list_get_entry(itr, channel_t, link_node);
+ chl = list_get_entry(itr, channellist_t, node);
+ ch = chl->chan;
links[i++] = ch->id;
}
sendmsg->payload.channelState->links = links;
char *message;
uint32_t *tree_id;
- message = malloc(strlen(client->username) + 32);
- 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(client->username) + 32);
+ tree_id = Memory_safeMalloc(1, sizeof(uint32_t));
*tree_id = 0;
sendmsg = Msg_create(TextMessage);
sendmsg->payload.textMessage->message = message;
if (msg->payload.userState->has_plugin_context) {
if (client->context)
free(client->context);
- client->context = malloc(msg->payload.userState->plugin_context.len);
- if (client->context == NULL)
- Log_fatal("Out of memory");
+ client->context = Memory_safeMalloc(1, msg->payload.userState->plugin_context.len);
memcpy(client->context, msg->payload.userState->plugin_context.data,
msg->payload.userState->plugin_context.len);
sendmsg->payload.userStats->version->os_version = strdup(target->os_version);
sendmsg->payload.userStats->n_celt_versions = target->codec_count;
- sendmsg->payload.userStats->celt_versions = malloc(sizeof(int32_t) * target->codec_count);
- if (!sendmsg->payload.userStats->celt_versions)
- Log_fatal("Out of memory");
+ sendmsg->payload.userStats->celt_versions
+ = Memory_safeMalloc(target->codec_count, sizeof(int32_t));
i = 0;
while (Client_codec_iterate(target, &codec_itr) != NULL)
sendmsg->payload.userStats->celt_versions[i++] = codec_itr->codec;
sendmsg->payload.userStats->opus = target->bOpus;
/* Address */
- sendmsg->payload.userStats->has_address = true;
- sendmsg->payload.userStats->address.data = malloc(sizeof(uint8_t) * 16);
- if (!sendmsg->payload.userStats->address.data)
- Log_fatal("Out of memory");
- memset(sendmsg->payload.userStats->address.data, 0, 16);
- /* ipv4 representation as ipv6 address. Supposedly correct. */
- memset(&sendmsg->payload.userStats->address.data[10], 0xff, 2); /* IPv4 */
- if(target->remote_tcp.ss_family == AF_INET)
- memcpy(&sendmsg->payload.userStats->address.data[12], &((struct sockaddr_in*)&target->remote_tcp)->sin_addr, 4);
- else
- memcpy(&sendmsg->payload.userStats->address.data[0], &((struct sockaddr_in6*)&target->remote_tcp)->sin6_addr, 16);
- sendmsg->payload.userStats->address.len = 16;
+ if (getBoolConf(SHOW_ADDRESSES)) {
+ sendmsg->payload.userStats->has_address = true;
+ sendmsg->payload.userStats->address.data
+ = Memory_safeMalloc(16, sizeof(uint8_t));
+ memset(sendmsg->payload.userStats->address.data, 0, 16);
+ /* ipv4 representation as ipv6 address. Supposedly correct. */
+ memset(&sendmsg->payload.userStats->address.data[10], 0xff, 2); /* IPv4 */
+ if(target->remote_tcp.ss_family == AF_INET)
+ memcpy(&sendmsg->payload.userStats->address.data[12], &((struct sockaddr_in*)&target->remote_tcp)->sin_addr, 4);
+ else
+ memcpy(&sendmsg->payload.userStats->address.data[0], &((struct sockaddr_in6*)&target->remote_tcp)->sin6_addr, 16);
+ sendmsg->payload.userStats->address.len = 16;
+ } else {
+ sendmsg->payload.userStats->has_address = false;
+ }
}
/* BW */
sendmsg->payload.userStats->has_bandwidth = true;