#include <time.h>
#include <string.h>
#include "log.h"
+#include "memory.h"
#include "list.h"
#include "ban.h"
#include "conf.h"
ban_t *ban;
char hexhash[41];
- ban = calloc(1, sizeof(ban_t));
- if (ban == NULL)
- Log_fatal("Out of memory");
+ ban = Memory_safeCalloc(1, sizeof(ban_t));
memcpy(ban->hash, client->hash, 20);
for (i = 0; i < n_bans; i++) {
Msg_banList_getEntry(msg, i, &address, &mask, &name, &hexhash, &reason, &start, &duration);
- ban = malloc(sizeof(ban_t));
- if (ban == NULL)
- Log_fatal("Out of memory");
+ ban = Memory_safeMalloc(1, sizeof(ban_t));
SSLi_hex2hash(hexhash, ban->hash);
if(memcmp(address, mappedBytes, 12) == 0) {
if (p == NULL) break;
reason = p;
- ban = malloc(sizeof(ban_t));
- if (ban == NULL)
- Log_fatal("Out of memory");
+ ban = Memory_safeMalloc(1, sizeof(ban_t));
memset(ban, 0, sizeof(ban_t));
SSLi_hex2hash(hexhash, ban->hash);
if (inet_pton(AF_INET, address, &ban->address) == 0) {
#include <stdlib.h>
#include <string.h>
#include "log.h"
+#include "memory.h"
#include "list.h"
#include "client.h"
#include "channel.h"
{
channel_t *ch;
- ch = malloc(sizeof(channel_t));
- if (ch == NULL)
- Log_fatal("out of memory");
+ ch = Memory_safeMalloc(1, sizeof(channel_t));
memset(ch, 0, sizeof(channel_t));
ch->id = id;
ch->name = strdup(name);
else
ch_dst = ch_itr;
- chl = malloc(sizeof(channellist_t));
- if(!chl)
- Log_fatal("Out of memory");
+ chl = Memory_safeMalloc(1, sizeof(channellist_t));
chl->chan = ch_dst;
init_list_entry(&chl->node);
list_add_tail(&chl->node, &ch_src->channel_links);
struct dlist *itr;
channel_t *sub;
- chl = malloc(sizeof(channellist_t));
- if(!chl)
- Log_fatal("Out of memory");
+ chl = Memory_safeMalloc(1, sizeof(channellist_t));
chl->chan = ch;
init_list_entry(&chl->node);
list_add_tail(&chl->node, head);
#include <stdlib.h>
#include <string.h>
#include "log.h"
+#include "memory.h"
#include "list.h"
#include "client.h"
#include "ssl.h"
void Client_codec_add(client_t *client, int codec)
{
- codec_t *cd = malloc(sizeof(codec_t));
- if (cd == NULL)
- Log_fatal("Out of memory");
+ codec_t *cd = Memory_safeMalloc(1, sizeof(codec_t));
init_list_entry(&cd->node);
cd->codec = codec;
list_add_tail(&cd->node, &client->codecs);
if (client->tokencount >= MAX_TOKENS)
return;
- token = malloc(sizeof(token_t));
- if (token == NULL)
- Log_fatal("Out of memory");
+ token = Memory_safeMalloc(1, sizeof(token_t));
init_list_entry(&token->node);
token->token = strdup(token_string);
if (token->token == NULL)
}
}
if (!found) {
- cd = malloc(sizeof(codec_t));
- if (!cd)
- Log_fatal("Out of memory");
+ cd = Memory_safeMalloc(1, sizeof(codec_t));
memset(cd, 0, sizeof(codec_t));
init_list_entry(&cd->node);
cd->codec = codec_itr->codec;
return -1;
}
- 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));
uint32_t *tree_id;
message_t *sendmsg = NULL;
- 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));
*tree_id = 0;
sendmsg = Msg_create(TextMessage);
sendmsg->payload.textMessage->message = message;
if (Util_clientAddressToPortUDP(client) != 0 && CryptState_isValid(&client->cryptState) &&
client->bUDP) {
#if defined(__LP64__)
- buf = mbuf = malloc(len + 4 + 16);
+ buf = mbuf = Memory_safeMalloc(1, len + 4 + 16);
buf += 4;
#else
- mbuf = buf = malloc(len + 4);
+ mbuf = buf = Memory_safeMalloc(1, len + 4);
#endif
- if (mbuf == NULL)
- Log_fatal("Out of memory");
-
CryptState_encrypt(&client->cryptState, data, buf, len);
#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
--- /dev/null
+/* Copyright (C) 2009-2014, Martin Johansson <martin@fatbob.nu>
+ Copyright (C) 2005-2014, Thorvald Natvig <thorvald@natvig.com>
+
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ - Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ - Neither the name of the Developers nor the names of its contributors may
+ be used to endorse or promote products derived from this software without
+ specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+#include <stdint.h>
+#include <unistd.h>
+
+#include "log.h"
+#include "memory.h"
+
+void * Memory_safeMalloc(size_t nmem, size_t size) {
+ // Check if we're going to overflow.
+ if (size && num > SIZE_MAX / size)
+ Log_fatal("Request for memory would've overflowed.");
+
+ // Allocate the memory requested.
+ void * retPtr = malloc(nmem * size);
+
+ // Check if we had an error.
+ if (retPtr == NULL)
+ Log_fatal("Out of memory.");
+
+ return retPtr;
+}
+
+void * Memory_safeCalloc(size_t nmem, size_t size) {
+ // Allocate the memory requested.
+ void * retPtr = calloc(nmem, size);
+
+ // Check if we had an error.
+ if (retPtr == NULL)
+ Log_fatal("Out of memory.");
+
+ return retPtr;
+}
--- /dev/null
+/* Copyright (C) 2009-2014, Martin Johansson <martin@fatbob.nu>
+ Copyright (C) 2005-2014, Thorvald Natvig <thorvald@natvig.com>
+
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ - Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ - Neither the name of the Developers nor the names of its contributors may
+ be used to endorse or promote products derived from this software without
+ specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+void * Memory_safeMalloc(size_t nmem, size_t size);
+void * Memory_safeCalloc(size_t nmem, size_t size);
#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));
- if(!links)
- Log_fatal("Out of memory");
-
+ 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;
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;
/* 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");
+ 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 */
#include "client.h"
#include "pds.h"
#include "log.h"
+#include "memory.h"
#define PREAMBLE_SIZE 6
static message_t *Msg_create_nopayload(messageType_t messageType)
{
- message_t *msg = malloc(sizeof(message_t));
+ message_t *msg = Memory_safeMalloc(1, sizeof(message_t));
- if (msg == NULL)
- Log_fatal("Out of memory");
memset(msg, 0, sizeof(message_t));
msg->refcount = 1;
msg->messageType = messageType;
switch (messageType) {
case Version:
- msg->payload.version = malloc(sizeof(MumbleProto__Version));
+ msg->payload.version = Memory_safeMalloc(1, sizeof(MumbleProto__Version));
mumble_proto__version__init(msg->payload.version);
break;
case UDPTunnel:
- msg->payload.UDPTunnel = malloc(sizeof(MumbleProto__UDPTunnel));
+ msg->payload.UDPTunnel = Memory_safeMalloc(1, sizeof(MumbleProto__UDPTunnel));
mumble_proto__udptunnel__init(msg->payload.UDPTunnel);
break;
case Authenticate:
- msg->payload.authenticate = malloc(sizeof(MumbleProto__Authenticate));
+ msg->payload.authenticate = Memory_safeMalloc(1, sizeof(MumbleProto__Authenticate));
mumble_proto__authenticate__init(msg->payload.authenticate);
break;
case Ping:
- msg->payload.ping = malloc(sizeof(MumbleProto__Ping));
+ msg->payload.ping = Memory_safeMalloc(1, sizeof(MumbleProto__Ping));
mumble_proto__ping__init(msg->payload.ping);
break;
case Reject:
- msg->payload.reject = malloc(sizeof(MumbleProto__Reject));
+ msg->payload.reject = Memory_safeMalloc(1, sizeof(MumbleProto__Reject));
mumble_proto__reject__init(msg->payload.reject);
break;
case ServerSync:
- msg->payload.serverSync = malloc(sizeof(MumbleProto__ServerSync));
+ msg->payload.serverSync = Memory_safeMalloc(1, sizeof(MumbleProto__ServerSync));
mumble_proto__server_sync__init(msg->payload.serverSync);
break;
case TextMessage:
- msg->payload.textMessage = malloc(sizeof(MumbleProto__TextMessage));
+ msg->payload.textMessage = Memory_safeMalloc(1, sizeof(MumbleProto__TextMessage));
mumble_proto__text_message__init(msg->payload.textMessage);
break;
case PermissionDenied:
- msg->payload.permissionDenied = malloc(sizeof(MumbleProto__PermissionDenied));
+ msg->payload.permissionDenied = Memory_safeMalloc(1, sizeof(MumbleProto__PermissionDenied));
mumble_proto__permission_denied__init(msg->payload.permissionDenied);
break;
case CryptSetup:
- msg->payload.cryptSetup = malloc(sizeof(MumbleProto__CryptSetup));
+ msg->payload.cryptSetup = Memory_safeMalloc(1, sizeof(MumbleProto__CryptSetup));
mumble_proto__crypt_setup__init(msg->payload.cryptSetup);
break;
case UserList:
- msg->payload.userList = malloc(sizeof(MumbleProto__UserList));
+ msg->payload.userList = Memory_safeMalloc(1, sizeof(MumbleProto__UserList));
mumble_proto__user_list__init(msg->payload.userList);
break;
case UserState:
- msg->payload.userState = malloc(sizeof(MumbleProto__UserState));
+ msg->payload.userState = Memory_safeMalloc(1, sizeof(MumbleProto__UserState));
mumble_proto__user_state__init(msg->payload.userState);
break;
case ChannelState:
- msg->payload.channelState = malloc(sizeof(MumbleProto__ChannelState));
+ msg->payload.channelState = Memory_safeMalloc(1, sizeof(MumbleProto__ChannelState));
mumble_proto__channel_state__init(msg->payload.channelState);
break;
case UserRemove:
- msg->payload.userRemove = malloc(sizeof(MumbleProto__UserRemove));
+ msg->payload.userRemove = Memory_safeMalloc(1, sizeof(MumbleProto__UserRemove));
mumble_proto__user_remove__init(msg->payload.userRemove);
break;
case VoiceTarget:
- msg->payload.voiceTarget = malloc(sizeof(MumbleProto__VoiceTarget));
+ msg->payload.voiceTarget = Memory_safeMalloc(1, sizeof(MumbleProto__VoiceTarget));
mumble_proto__voice_target__init(msg->payload.voiceTarget);
break;
case CodecVersion:
- msg->payload.codecVersion = malloc(sizeof(MumbleProto__CodecVersion));
+ msg->payload.codecVersion = Memory_safeMalloc(1, sizeof(MumbleProto__CodecVersion));
mumble_proto__codec_version__init(msg->payload.codecVersion);
break;
case PermissionQuery:
- msg->payload.permissionQuery = malloc(sizeof(MumbleProto__PermissionQuery));
+ msg->payload.permissionQuery = Memory_safeMalloc(1, sizeof(MumbleProto__PermissionQuery));
mumble_proto__permission_query__init(msg->payload.permissionQuery);
break;
case ChannelRemove:
- msg->payload.channelRemove = malloc(sizeof(MumbleProto__ChannelRemove));
+ msg->payload.channelRemove = Memory_safeMalloc(1, sizeof(MumbleProto__ChannelRemove));
mumble_proto__channel_remove__init(msg->payload.channelRemove);
break;
case UserStats:
- msg->payload.userStats = malloc(sizeof(MumbleProto__UserStats));
+ msg->payload.userStats = Memory_safeMalloc(1, sizeof(MumbleProto__UserStats));
mumble_proto__user_stats__init(msg->payload.userStats);
- msg->payload.userStats->from_client = malloc(sizeof(MumbleProto__UserStats__Stats));
+ msg->payload.userStats->from_client = Memory_safeMalloc(1, sizeof(MumbleProto__UserStats__Stats));
mumble_proto__user_stats__stats__init(msg->payload.userStats->from_client);
- msg->payload.userStats->from_server = malloc(sizeof(MumbleProto__UserStats__Stats));
+ msg->payload.userStats->from_server = Memory_safeMalloc(1, sizeof(MumbleProto__UserStats__Stats));
mumble_proto__user_stats__stats__init(msg->payload.userStats->from_server);
- msg->payload.userStats->version = malloc(sizeof(MumbleProto__Version));
+ msg->payload.userStats->version = Memory_safeMalloc(1, sizeof(MumbleProto__Version));
mumble_proto__version__init(msg->payload.userStats->version);
- if (!msg->payload.userStats || !msg->payload.userStats->from_client ||
- !msg->payload.userStats->from_server || !msg->payload.userStats->version)
- Log_fatal("Out of memory");
break;
case ServerConfig:
- msg->payload.serverConfig = malloc(sizeof(MumbleProto__ServerConfig));
+ msg->payload.serverConfig = Memory_safeMalloc(1, sizeof(MumbleProto__ServerConfig));
mumble_proto__server_config__init(msg->payload.serverConfig);
break;
message_t *msg = Msg_create_nopayload(BanList);
int i;
- msg->payload.banList = malloc(sizeof(MumbleProto__BanList));
- if (msg->payload.banList == NULL)
- Log_fatal("Out of memory");
+ msg->payload.banList = Memory_safeMalloc(1, sizeof(MumbleProto__BanList));
memset(msg->payload.banList, 0, sizeof(MumbleProto__BanList));
mumble_proto__ban_list__init(msg->payload.banList);
msg->payload.banList->n_bans = n_bans;
- msg->payload.banList->bans = malloc(sizeof(MumbleProto__BanList__BanEntry *) * n_bans);
- if (msg->payload.banList->bans == NULL)
- Log_fatal("Out of memory");
+ msg->payload.banList->bans = Memory_safeMalloc(1, sizeof(MumbleProto__BanList__BanEntry *) * n_bans);
for (i = 0; i < n_bans; i++) {
- msg->payload.banList->bans[i] = malloc(sizeof(MumbleProto__BanList__BanEntry));
- if (msg->payload.banList->bans[i] == NULL)
- Log_fatal("Out of memory");
+ msg->payload.banList->bans[i] = Memory_safeMalloc(1, sizeof(MumbleProto__BanList__BanEntry));
memset(msg->payload.banList->bans[i], 0, sizeof(MumbleProto__BanList__BanEntry));
mumble_proto__ban_list__ban_entry__init(msg->payload.banList->bans[i]);
}
{
MumbleProto__BanList__BanEntry *entry = msg->payload.banList->bans[index];
- entry->address.data = malloc(16);
- if (!entry->address.data)
- Log_fatal("Out of memory");
+ entry->address.data = Memory_safeMalloc(1, 16);
memcpy(entry->address.data, address, 16);
entry->address.len = 16;
entry->mask = mask;
msg = Msg_create_nopayload(UDPTunnel);
msg->unpacked = false;
- msg->payload.UDPTunnel = malloc(sizeof(struct _MumbleProto__UDPTunnel));
- if (msg->payload.UDPTunnel == NULL)
- Log_fatal("Out of memory");
- msg->payload.UDPTunnel->packet.data = malloc(size);
- if (msg->payload.UDPTunnel->packet.data == NULL)
- Log_fatal("Out of memory");
+ msg->payload.UDPTunnel = Memory_safeMalloc(1, sizeof(struct _MumbleProto__UDPTunnel));
+ msg->payload.UDPTunnel->packet.data = Memory_safeMalloc(1, size);
memcpy(msg->payload.UDPTunnel->packet.data, data, size);
msg->payload.UDPTunnel->packet.len = size;
return msg;
#include <stdlib.h>
#include "pds.h"
#include "log.h"
+#include "memory.h"
/*
* Data serialization functions below
pds_t *Pds_create(uint8_t *buf, int size)
{
- pds_t *pds = malloc(sizeof(pds_t));
- if (pds == NULL)
- Log_fatal("Out of memory");
+ pds_t *pds = Memory_safeMalloc(1, sizeof(pds_t));
pds->data = buf;
pds->offset = pds->overshoot = 0;
pds->maxsize = size;
#include "client.h"
#include "conf.h"
#include "log.h"
+#include "memory.h"
#include "timer.h"
#include "version.h"
#include "util.h"
/* Initialize the address structures for IPv4 and IPv6 */
struct sockaddr_storage** Server_setupAddressesAndPorts()
{
- struct sockaddr_storage** addresses = calloc(2, sizeof(void*));
- if(!addresses)
- Log_fatal("Not enough memory to allocate addresses");
+ struct sockaddr_storage** addresses = Memory_safeCalloc(2, sizeof(void*));
- struct sockaddr_storage* v4address = calloc(1, sizeof(struct sockaddr_storage));
- if(!v4address)
- Log_fatal("Not enough memory to allocate IPv4 address");
+ struct sockaddr_storage* v4address = Memory_safeCalloc(1, sizeof(struct sockaddr_storage));
v4address->ss_family = AF_INET;
-
- struct sockaddr_storage* v6address = calloc(1, sizeof(struct sockaddr_storage));
- if(!v6address)
- Log_fatal("Not enough memory to allocate IPv6 address");
+ struct sockaddr_storage* v6address = Memory_safeCalloc(1, sizeof(struct sockaddr_storage));
v6address->ss_family = AF_INET6;
#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
int val = 0;
int sockets[2] = {-1, -1};
- if((udpsocks = calloc(nofServerSocks / 2, sizeof(int))) == NULL)
- Log_fatal("Out of memory (%s:%s)", __FILE__, __LINE__);
+ udpsocks = Memory_safeCalloc(nofServerSocks / 2, sizeof(int))
if (hasv4) {
sockets[0] = socket(PF_INET, SOCK_DGRAM, 0);
checkIPversions();
/* max clients + server sokets + client connecting that will be disconnected */
- if ((pollfds = calloc((getIntConf(MAX_CLIENTS) + nofServerSocks + 1) , sizeof(struct pollfd))) == NULL)
- Log_fatal("out of memory");
+ pollfds = Memory_safeCalloc((getIntConf(MAX_CLIENTS) + nofServerSocks + 1) , sizeof(struct pollfd))
/* Figure out bind address and port */
struct sockaddr_storage** addresses = Server_setupAddressesAndPorts();
#include "ssl.h"
#include "conf.h"
#include "log.h"
+#include "memory.h"
#include <stdlib.h>
SSL_handle_t * SSLi_newconnection( int * fileDescriptor, bool_t * isSSLReady )
{
- gnutls_session_t * session = calloc(1, sizeof(gnutls_session_t));
+ gnutls_session_t * session
+ = Memory_safeCalloc(1, sizeof(gnutls_session_t));
gnutls_init(session, GNUTLS_SERVER);
gnutls_priority_set(*session, cipherCache);
#include "conf.h"
#include "log.h"
+#include "memory.h"
#include "ssl.h"
/*
Log_debug("%s", SSL_CIPHER_get_name(cipher));
cipherstringlen += strlen(SSL_CIPHER_get_name(cipher)) + 1;
}
- cipherstring = malloc(cipherstringlen + 1);
- if (cipherstring == NULL)
- Log_fatal("Out of memory");
+ cipherstring = Memory_safeMalloc(1, cipherstringlen + 1);
for (i = 0; (cipher = sk_SSL_CIPHER_value(cipherlist_new, i)) != NULL; i++) {
offset += sprintf(cipherstring + offset, "%s:", SSL_CIPHER_get_name(cipher));
}
}
len = i2d_X509(x509, NULL);
- buf = malloc(len);
- if (buf == NULL) {
- Log_fatal("malloc");
- }
+ buf = Memory_safeMalloc(1, len);
p = buf;
i2d_X509(x509, &p);
*/
#include "conf.h"
#include "log.h"
+#include "memory.h"
#include "ssl.h"
#include <stdlib.h>
ssl_session *ssn;
int rc;
- ssl = calloc(1, sizeof(ssl_context));
- ssn = calloc(1, sizeof(ssl_session));
- if (!ssl || !ssn)
- Log_fatal("Out of memory");
+ ssl = Memory_safeCalloc(1, sizeof(ssl_context));
+ ssn = Memory_safeCalloc(1, sizeof(ssl_session));
rc = ssl_init(ssl);
if (rc != 0 )
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "util.h"
+#include "memory.h"
char* Util_addressToString(struct sockaddr_storage *address)
{
char* addressString = NULL;
if (address->ss_family == AF_INET) {
- addressString = malloc(INET_ADDRSTRLEN);
+ addressString = Memory_safeMalloc(1, INET_ADDRSTRLEN);
inet_ntop(AF_INET, &((struct sockaddr_in *)address)->sin_addr, addressString, INET_ADDRSTRLEN);
} else if(address->ss_family == AF_INET6) {
- addressString = malloc(INET6_ADDRSTRLEN);
+ addressString = Memory_safeMalloc(1, INET6_ADDRSTRLEN);
inet_ntop(AF_INET6, &((struct sockaddr_in6 *)address)->sin6_addr, addressString, INET6_ADDRSTRLEN);
}
#include <string.h>
#include "voicetarget.h"
#include "log.h"
+#include "memory.h"
void Voicetarget_add_session(client_t *client, int targetId, int sessionId)
{
int i;
Voicetarget_del_id(client, targetId);
- newtarget = malloc(sizeof(voicetarget_t));
- if (!newtarget)
- Log_fatal("Out of memory");
- memset(newtarget, 0, sizeof(voicetarget_t));
+ newtarget = Memory_safeCalloc(1, sizeof(voicetarget_t));
for (i = 0; i < TARGET_MAX_CHANNELS; i++)
newtarget->channels[i].channel = -1;
for (i = 0; i < TARGET_MAX_SESSIONS; i++)