summaryrefslogtreecommitdiffstats
path: root/src/peer.c
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2014-08-02 00:53:47 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2014-08-02 00:53:47 +0200
commit546ac7936340312cf272969ff83317ae4d50d2b4 (patch)
tree7ecadca11430c8624d9f80aae7c348fa4d65b969 /src/peer.c
parentb22364f4af3564f0dd9a5f4e150bb09747bd5c4e (diff)
downloadfastd-546ac7936340312cf272969ff83317ae4d50d2b4.tar
fastd-546ac7936340312cf272969ff83317ae4d50d2b4.zip
Introduce and use alloc helpers
These new helpers will terminate fastd on allocation failures and add some additional convenience (allow strdup with NULL; typesafe new(type) macros).
Diffstat (limited to 'src/peer.c')
-rw-r--r--src/peer.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/peer.c b/src/peer.c
index 9bec0f0..8ff40dc 100644
--- a/src/peer.c
+++ b/src/peer.c
@@ -350,7 +350,7 @@ static void init_handshake(fastd_peer_t *peer) {
/** Handles an asynchronous DNS resolve response */
void fastd_peer_handle_resolve(fastd_peer_t *peer, fastd_remote_t *remote, size_t n_addresses, const fastd_peer_address_t *addresses) {
free(remote->addresses);
- remote->addresses = malloc(n_addresses*sizeof(fastd_peer_address_t));
+ remote->addresses = fastd_new_array(n_addresses, fastd_peer_address_t);
memcpy(remote->addresses, addresses, n_addresses*sizeof(fastd_peer_address_t));
remote->n_addresses = n_addresses;
@@ -432,7 +432,7 @@ static void delete_peer(fastd_peer_t *peer) {
/** Allocates a new peer config */
fastd_peer_config_t* fastd_peer_config_new(fastd_peer_group_t *group) {
- fastd_peer_config_t *peer = calloc(1, sizeof(fastd_peer_config_t));
+ fastd_peer_config_t *peer = fastd_new0(fastd_peer_config_t);
peer->group = group;
return peer;
@@ -707,7 +707,7 @@ bool fastd_peer_may_connect(fastd_peer_t *peer) {
/** Create a new peer */
fastd_peer_t* fastd_peer_add(fastd_peer_config_t *peer_conf) {
- fastd_peer_t *peer = calloc(1, sizeof(fastd_peer_t));
+ fastd_peer_t *peer = fastd_new0(fastd_peer_t);
peer->id = ctx.next_peer_id++;
@@ -723,7 +723,7 @@ fastd_peer_t* fastd_peer_add(fastd_peer_config_t *peer_conf) {
if (!remote_config->hostname) {
remote.n_addresses = 1;
- remote.addresses = malloc(sizeof(fastd_peer_address_t));
+ remote.addresses = fastd_new(fastd_peer_address_t);
remote.addresses[0] = remote_config->address;
}