From 546ac7936340312cf272969ff83317ae4d50d2b4 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sat, 2 Aug 2014 00:53:47 +0200 Subject: 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). --- src/protocols/ec25519_fhmqvc/ec25519_fhmqvc.c | 4 ++-- src/protocols/ec25519_fhmqvc/handshake.c | 2 +- src/protocols/ec25519_fhmqvc/state.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src/protocols') diff --git a/src/protocols/ec25519_fhmqvc/ec25519_fhmqvc.c b/src/protocols/ec25519_fhmqvc/ec25519_fhmqvc.c index 86acbec..f9bf1f7 100644 --- a/src/protocols/ec25519_fhmqvc/ec25519_fhmqvc.c +++ b/src/protocols/ec25519_fhmqvc/ec25519_fhmqvc.c @@ -59,7 +59,7 @@ static inline void check_session_refresh(fastd_peer_t *peer) { /** Initializes the protocol-specific configuration */ static fastd_protocol_config_t* protocol_init(void) { - fastd_protocol_config_t *protocol_config = malloc(sizeof(fastd_protocol_config_t)); + fastd_protocol_config_t *protocol_config = fastd_new(fastd_protocol_config_t); if (!conf.secret) exit_error("no secret key configured"); @@ -100,7 +100,7 @@ static void protocol_peer_configure(fastd_peer_config_t *peer_conf) { return; } - peer_conf->protocol_config = malloc(sizeof(fastd_protocol_peer_config_t)); + peer_conf->protocol_config = fastd_new(fastd_protocol_peer_config_t); peer_conf->protocol_config->public_key = key; if (memcmp(&peer_conf->protocol_config->public_key, &conf.protocol_config->key.public, PUBLICKEYBYTES) == 0) diff --git a/src/protocols/ec25519_fhmqvc/handshake.c b/src/protocols/ec25519_fhmqvc/handshake.c index 99f1829..9a1c8de 100644 --- a/src/protocols/ec25519_fhmqvc/handshake.c +++ b/src/protocols/ec25519_fhmqvc/handshake.c @@ -580,7 +580,7 @@ static fastd_peer_t * add_temporary(fastd_socket_t *sock, const fastd_peer_addre fastd_peer_t *peer = fastd_peer_add(NULL); - peer->protocol_config = malloc(sizeof(fastd_protocol_peer_config_t)); + peer->protocol_config = fastd_new(fastd_protocol_peer_config_t); memcpy(&peer->protocol_config->public_key, key, PUBLICKEYBYTES); /* Ugly hack */ diff --git a/src/protocols/ec25519_fhmqvc/state.c b/src/protocols/ec25519_fhmqvc/state.c index 451e31d..d4a2a0e 100644 --- a/src/protocols/ec25519_fhmqvc/state.c +++ b/src/protocols/ec25519_fhmqvc/state.c @@ -37,7 +37,7 @@ /** Allocates the protocol-specific state */ static void init_protocol_state(void) { if (!ctx.protocol_state) { - ctx.protocol_state = calloc(1, sizeof(fastd_protocol_state_t)); + ctx.protocol_state = fastd_new0(fastd_protocol_state_t); ctx.protocol_state->prev_handshake_key.preferred_till = ctx.now; ctx.protocol_state->handshake_key.preferred_till = ctx.now; @@ -84,7 +84,7 @@ void fastd_protocol_ec25519_fhmqvc_init_peer_state(fastd_peer_t *peer) { if (peer->protocol_state) exit_bug("tried to reinit peer state"); - peer->protocol_state = calloc(1, sizeof(fastd_protocol_peer_state_t)); + peer->protocol_state = fastd_new0(fastd_protocol_peer_state_t); peer->protocol_state->last_serial = ctx.protocol_state->handshake_key.serial; } -- cgit v1.2.3