Rename xmalloc_and_zero() to xzalloc().
The former name is more or less only used by tinc, the latter is used by other projects as well, and shorter as well.
This commit is contained in:
parent
9b9230a0a7
commit
5b07039b07
16 changed files with 24 additions and 24 deletions
|
@ -71,7 +71,7 @@ void exit_configuration(splay_tree_t ** config_tree) {
|
||||||
}
|
}
|
||||||
|
|
||||||
config_t *new_config(void) {
|
config_t *new_config(void) {
|
||||||
return xmalloc_and_zero(sizeof(config_t));
|
return xzalloc(sizeof(config_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
void free_config(config_t *cfg) {
|
void free_config(config_t *cfg) {
|
||||||
|
|
|
@ -48,7 +48,7 @@ void exit_connections(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
connection_t *new_connection(void) {
|
connection_t *new_connection(void) {
|
||||||
return xmalloc_and_zero(sizeof(connection_t));
|
return xzalloc(sizeof(connection_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
void free_connection(connection_t *c) {
|
void free_connection(connection_t *c) {
|
||||||
|
|
|
@ -70,7 +70,7 @@ void exit_edges(void) {
|
||||||
/* Creation and deletion of connection elements */
|
/* Creation and deletion of connection elements */
|
||||||
|
|
||||||
edge_t *new_edge(void) {
|
edge_t *new_edge(void) {
|
||||||
return xmalloc_and_zero(sizeof(edge_t));
|
return xzalloc(sizeof(edge_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
void free_edge(edge_t *e) {
|
void free_edge(edge_t *e) {
|
||||||
|
|
|
@ -48,7 +48,7 @@ void freeaddrinfo(struct addrinfo *ai) {
|
||||||
static struct addrinfo *malloc_ai(uint16_t port, uint32_t addr) {
|
static struct addrinfo *malloc_ai(uint16_t port, uint32_t addr) {
|
||||||
struct addrinfo *ai;
|
struct addrinfo *ai;
|
||||||
|
|
||||||
ai = xmalloc_and_zero(sizeof(struct addrinfo) + sizeof(struct sockaddr_in));
|
ai = xzalloc(sizeof(struct addrinfo) + sizeof(struct sockaddr_in));
|
||||||
|
|
||||||
ai->ai_addr = (struct sockaddr *)(ai + 1);
|
ai->ai_addr = (struct sockaddr *)(ai + 1);
|
||||||
ai->ai_addrlen = sizeof(struct sockaddr_in);
|
ai->ai_addrlen = sizeof(struct sockaddr_in);
|
||||||
|
|
|
@ -52,11 +52,11 @@ static uint32_t modulo(uint32_t hash, size_t n) {
|
||||||
/* (De)allocation */
|
/* (De)allocation */
|
||||||
|
|
||||||
hash_t *hash_alloc(size_t n, size_t size) {
|
hash_t *hash_alloc(size_t n, size_t size) {
|
||||||
hash_t *hash = xmalloc_and_zero(sizeof *hash);
|
hash_t *hash = xzalloc(sizeof *hash);
|
||||||
hash->n = n;
|
hash->n = n;
|
||||||
hash->size = size;
|
hash->size = size;
|
||||||
hash->keys = xmalloc_and_zero(hash->n * hash->size);
|
hash->keys = xzalloc(hash->n * hash->size);
|
||||||
hash->values = xmalloc_and_zero(hash->n * sizeof *hash->values);
|
hash->values = xzalloc(hash->n * sizeof *hash->values);
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
/* (De)constructors */
|
/* (De)constructors */
|
||||||
|
|
||||||
list_t *list_alloc(list_action_t delete) {
|
list_t *list_alloc(list_action_t delete) {
|
||||||
list_t *list = xmalloc_and_zero(sizeof(list_t));
|
list_t *list = xzalloc(sizeof(list_t));
|
||||||
list->delete = delete;
|
list->delete = delete;
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
|
@ -37,7 +37,7 @@ void list_free(list_t *list) {
|
||||||
}
|
}
|
||||||
|
|
||||||
list_node_t *list_alloc_node(void) {
|
list_node_t *list_alloc_node(void) {
|
||||||
return xmalloc_and_zero(sizeof(list_node_t));
|
return xzalloc(sizeof(list_node_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
void list_free_node(list_t *list, list_node_t *node) {
|
void list_free_node(list_t *list, list_node_t *node) {
|
||||||
|
|
|
@ -224,7 +224,7 @@ static void periodic_handler(void *data) {
|
||||||
|
|
||||||
if(!found) {
|
if(!found) {
|
||||||
logger(DEBUG_CONNECTIONS, LOG_INFO, "Autoconnecting to %s", n->name);
|
logger(DEBUG_CONNECTIONS, LOG_INFO, "Autoconnecting to %s", n->name);
|
||||||
outgoing_t *outgoing = xmalloc_and_zero(sizeof *outgoing);
|
outgoing_t *outgoing = xzalloc(sizeof *outgoing);
|
||||||
outgoing->name = xstrdup(n->name);
|
outgoing->name = xstrdup(n->name);
|
||||||
list_insert_tail(outgoing_list, outgoing);
|
list_insert_tail(outgoing_list, outgoing);
|
||||||
setup_outgoing_connection(outgoing);
|
setup_outgoing_connection(outgoing);
|
||||||
|
|
|
@ -674,7 +674,7 @@ void try_outgoing_connections(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!found) {
|
if(!found) {
|
||||||
outgoing_t *outgoing = xmalloc_and_zero(sizeof *outgoing);
|
outgoing_t *outgoing = xzalloc(sizeof *outgoing);
|
||||||
outgoing->name = name;
|
outgoing->name = name;
|
||||||
list_insert_tail(outgoing_list, outgoing);
|
list_insert_tail(outgoing_list, outgoing);
|
||||||
setup_outgoing_connection(outgoing);
|
setup_outgoing_connection(outgoing);
|
||||||
|
|
|
@ -50,9 +50,9 @@ void exit_nodes(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
node_t *new_node(void) {
|
node_t *new_node(void) {
|
||||||
node_t *n = xmalloc_and_zero(sizeof *n);
|
node_t *n = xzalloc(sizeof *n);
|
||||||
|
|
||||||
if(replaywin) n->late = xmalloc_and_zero(replaywin);
|
if(replaywin) n->late = xzalloc(replaywin);
|
||||||
n->subnet_tree = new_subnet_tree();
|
n->subnet_tree = new_subnet_tree();
|
||||||
n->edge_tree = new_edge_tree();
|
n->edge_tree = new_edge_tree();
|
||||||
n->mtu = MTU;
|
n->mtu = MTU;
|
||||||
|
|
|
@ -40,7 +40,7 @@ typedef struct cipher_counter {
|
||||||
} cipher_counter_t;
|
} cipher_counter_t;
|
||||||
|
|
||||||
static cipher_t *cipher_open(const EVP_CIPHER *evp_cipher) {
|
static cipher_t *cipher_open(const EVP_CIPHER *evp_cipher) {
|
||||||
cipher_t *cipher = xmalloc_and_zero(sizeof *cipher);
|
cipher_t *cipher = xzalloc(sizeof *cipher);
|
||||||
cipher->cipher = evp_cipher;
|
cipher->cipher = evp_cipher;
|
||||||
EVP_CIPHER_CTX_init(&cipher->ctx);
|
EVP_CIPHER_CTX_init(&cipher->ctx);
|
||||||
|
|
||||||
|
@ -135,7 +135,7 @@ bool cipher_set_counter_key(cipher_t *cipher, void *key) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!cipher->counter)
|
if(!cipher->counter)
|
||||||
cipher->counter = xmalloc_and_zero(sizeof *cipher->counter);
|
cipher->counter = xzalloc(sizeof *cipher->counter);
|
||||||
else
|
else
|
||||||
cipher->counter->n = 0;
|
cipher->counter->n = 0;
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
#include "../logger.h"
|
#include "../logger.h"
|
||||||
|
|
||||||
static digest_t *digest_open(const EVP_MD *evp_md, int maclength) {
|
static digest_t *digest_open(const EVP_MD *evp_md, int maclength) {
|
||||||
digest_t *digest = xmalloc_and_zero(sizeof *digest);
|
digest_t *digest = xzalloc(sizeof *digest);
|
||||||
digest->digest = evp_md;
|
digest->digest = evp_md;
|
||||||
|
|
||||||
int digestlen = EVP_MD_size(digest->digest);
|
int digestlen = EVP_MD_size(digest->digest);
|
||||||
|
|
|
@ -238,7 +238,7 @@ static void splay_bottom_up(splay_tree_t *tree, splay_node_t *node) {
|
||||||
splay_tree_t *splay_alloc_tree(splay_compare_t compare, splay_action_t delete) {
|
splay_tree_t *splay_alloc_tree(splay_compare_t compare, splay_action_t delete) {
|
||||||
splay_tree_t *tree;
|
splay_tree_t *tree;
|
||||||
|
|
||||||
tree = xmalloc_and_zero(sizeof(splay_tree_t));
|
tree = xzalloc(sizeof(splay_tree_t));
|
||||||
tree->compare = compare;
|
tree->compare = compare;
|
||||||
tree->delete = delete;
|
tree->delete = delete;
|
||||||
|
|
||||||
|
@ -250,7 +250,7 @@ void splay_free_tree(splay_tree_t *tree) {
|
||||||
}
|
}
|
||||||
|
|
||||||
splay_node_t *splay_alloc_node(void) {
|
splay_node_t *splay_alloc_node(void) {
|
||||||
return xmalloc_and_zero(sizeof(splay_node_t));
|
return xzalloc(sizeof(splay_node_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
void splay_free_node(splay_tree_t *tree, splay_node_t *node) {
|
void splay_free_node(splay_tree_t *tree, splay_node_t *node) {
|
||||||
|
|
|
@ -79,7 +79,7 @@ void free_subnet_tree(splay_tree_t *subnet_tree) {
|
||||||
/* Allocating and freeing space for subnets */
|
/* Allocating and freeing space for subnets */
|
||||||
|
|
||||||
subnet_t *new_subnet(void) {
|
subnet_t *new_subnet(void) {
|
||||||
return xmalloc_and_zero(sizeof(subnet_t));
|
return xzalloc(sizeof(subnet_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
void free_subnet(subnet_t *subnet) {
|
void free_subnet(subnet_t *subnet) {
|
||||||
|
|
|
@ -792,7 +792,7 @@ static int cmd_start(int argc, char *argv[]) {
|
||||||
c = "tincd";
|
c = "tincd";
|
||||||
|
|
||||||
int nargc = 0;
|
int nargc = 0;
|
||||||
char **nargv = xmalloc_and_zero((optind + argc) * sizeof *nargv);
|
char **nargv = xzalloc((optind + argc) * sizeof *nargv);
|
||||||
|
|
||||||
nargv[nargc++] = c;
|
nargv[nargc++] = c;
|
||||||
for(int i = 1; i < optind; i++)
|
for(int i = 1; i < optind; i++)
|
||||||
|
|
|
@ -108,7 +108,7 @@ static void update(int fd) {
|
||||||
found = ns;
|
found = ns;
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
found = xmalloc_and_zero(sizeof *found);
|
found = xzalloc(sizeof *found);
|
||||||
found->name = xstrdup(name);
|
found->name = xstrdup(name);
|
||||||
list_insert_before(&node_list, node, found);
|
list_insert_before(&node_list, node, found);
|
||||||
changed = true;
|
changed = true;
|
||||||
|
@ -117,7 +117,7 @@ static void update(int fd) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!found) {
|
if(!found) {
|
||||||
found = xmalloc_and_zero(sizeof *found);
|
found = xzalloc(sizeof *found);
|
||||||
found->name = xstrdup(name);
|
found->name = xstrdup(name);
|
||||||
list_insert_tail(&node_list, found);
|
list_insert_tail(&node_list, found);
|
||||||
changed = true;
|
changed = true;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
xalloc.h -- malloc and related fuctions with out of memory checking
|
xalloc.h -- malloc and related fuctions with out of memory checking
|
||||||
Copyright (C) 1990, 91, 92, 93, 94, 95, 96, 97 Free Software Foundation, Inc.
|
Copyright (C) 1990, 91, 92, 93, 94, 95, 96, 97 Free Software Foundation, Inc.
|
||||||
Copyright (C) 2011 Guus Sliepen <guus@tinc-vpn.org>
|
Copyright (C) 2011-2013 Guus Sliepen <guus@tinc-vpn.org>
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
This program is free software; you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
@ -27,7 +27,7 @@ static inline void *xmalloc(size_t n) {
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void *xmalloc_and_zero(size_t n) {
|
static inline void *xzalloc(size_t n) {
|
||||||
void *p = calloc(1, n);
|
void *p = calloc(1, n);
|
||||||
if(!p)
|
if(!p)
|
||||||
abort();
|
abort();
|
||||||
|
|
Loading…
Reference in a new issue