aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/libmdsserver/client-list.c13
-rw-r--r--src/libmdsserver/linked-list.c45
-rw-r--r--src/libmdsserver/macros.h51
-rw-r--r--src/libmdsserver/util.c3
-rw-r--r--src/mds-base.c3
-rw-r--r--src/mds-kbdc/builtin-functions.c26
-rw-r--r--src/mds-kbdc/callables.c33
-rw-r--r--src/mds-kbdc/compile-layout.c30
-rw-r--r--src/mds-kbdc/include-stack.c6
-rw-r--r--src/mds-kbdc/make-tree.c16
-rw-r--r--src/mds-kbdc/parsed.c5
-rw-r--r--src/mds-kbdc/paths.c2
-rw-r--r--src/mds-kbdc/process-includes.c2
-rw-r--r--src/mds-kbdc/raw-data.c3
-rw-r--r--src/mds-kbdc/tree.c2
-rw-r--r--src/mds-registry/reexec.c6
-rw-r--r--src/mds-registry/registry.c10
-rw-r--r--src/mds-registry/slave.c12
-rw-r--r--src/mds-respawn.c2
-rw-r--r--src/mds-server/interception-condition.c2
-rw-r--r--src/mds-server/interceptors.c2
-rw-r--r--src/mds-server/mds-server.c4
-rw-r--r--src/mds-server/receiving.c10
-rw-r--r--src/mds.c7
24 files changed, 151 insertions, 144 deletions
diff --git a/src/libmdsserver/client-list.c b/src/libmdsserver/client-list.c
index 24403cb..33b6844 100644
--- a/src/libmdsserver/client-list.c
+++ b/src/libmdsserver/client-list.c
@@ -106,7 +106,7 @@ int client_list_clone(const client_list_t* restrict this, client_list_t* restric
out->clients = NULL;
- fail_if ((new_clients = malloc(n)) == NULL);
+ fail_if (xbmalloc(new_clients, n));
out->clients = new_clients;
@@ -221,8 +221,6 @@ void client_list_marshal(const client_list_t* restrict this, char* restrict data
*/
int client_list_unmarshal(client_list_t* restrict this, char* restrict data)
{
- size_t n;
-
/* buf_get(data, int, 0, CLIENT_LIST_T_VERSION); */
buf_next(data, int, 1);
@@ -231,13 +229,8 @@ int client_list_unmarshal(client_list_t* restrict this, char* restrict data)
buf_get_next(data, size_t, this->capacity);
buf_get_next(data, size_t, this->size);
- n = this->capacity * sizeof(uint64_t);
-
- fail_if ((this->clients = malloc(n)) == NULL);
-
- n = this->size * sizeof(uint64_t);
-
- memcpy(this->clients, data, n);
+ fail_if (xmalloc(this->clients, this->capacity, uint64_t));
+ memcpy(this->clients, data, this->size * sizeof(uint64_t));
return 0;
fail:
diff --git a/src/libmdsserver/linked-list.c b/src/libmdsserver/linked-list.c
index f00daf3..1dea87a 100644
--- a/src/libmdsserver/linked-list.c
+++ b/src/libmdsserver/linked-list.c
@@ -125,10 +125,10 @@ int linked_list_clone(const linked_list_t* restrict this, linked_list_t* restric
out->previous = NULL;
out->reusable = NULL;
- fail_if ((new_values = malloc(n)) == NULL);
- fail_if ((new_next = malloc(n)) == NULL);
- fail_if ((new_previous = malloc(n)) == NULL);
- fail_if ((new_reusable = malloc(n)) == NULL);
+ fail_if (xbmalloc(new_values, n));
+ fail_if (xbmalloc(new_next, n));
+ fail_if (xbmalloc(new_previous, n));
+ fail_if (xbmalloc(new_reusable, n));
out->values = new_values;
out->next = new_next;
@@ -242,31 +242,22 @@ int linked_list_pack(linked_list_t* restrict this)
*/
static ssize_t linked_list_get_next(linked_list_t* restrict this)
{
+ size_t* tmp_values;
+ ssize_t* tmp;
+
if (this->reuse_head > 0)
return this->reusable[--(this->reuse_head)];
if (this->end == this->capacity)
{
- size_t* old_values;
- ssize_t* old;
-
if ((ssize_t)(this->end) < 0)
fail_if ((errno = ENOMEM));
this->capacity <<= 1;
-
-#define __realloc(new_var, old_var, type) \
- if ((new_var = realloc(old_var = new_var, this->capacity * sizeof(type))) == NULL) \
- { \
- new_var = old_var; \
- fail_if (1); \
- }
-
- __realloc(this->values, old_values, size_t)
- __realloc(this->next, old, ssize_t)
- __realloc(this->previous, old, ssize_t)
- __realloc(this->reusable, old, ssize_t)
-
-#undef __realloc
+
+ fail_if (yrealloc(tmp_values, this->values, this->capacity, size_t));
+ fail_if (yrealloc(tmp, this->next, this->capacity, ssize_t));
+ fail_if (yrealloc(tmp, this->previous, this->capacity, ssize_t));
+ fail_if (yrealloc(tmp, this->reusable, this->capacity, ssize_t));
}
return (ssize_t)(this->end++);
fail:
@@ -438,8 +429,6 @@ void linked_list_marshal(const linked_list_t* restrict this, char* restrict data
*/
int linked_list_unmarshal(linked_list_t* restrict this, char* restrict data)
{
- size_t n;
-
/* buf_get(data, int, 0, LINKED_LIST_T_VERSION); */
buf_next(data, int, 1);
@@ -454,12 +443,10 @@ int linked_list_unmarshal(linked_list_t* restrict this, char* restrict data)
buf_get(data, ssize_t, 3, this->edge);
buf_next(data, size_t, 4);
- n = this->capacity * sizeof(size_t);
-
- fail_if ((this->reusable = malloc(n)) == NULL);
- fail_if ((this->values = malloc(n)) == NULL);
- fail_if ((this->next = malloc(n)) == NULL);
- fail_if ((this->previous = malloc(n)) == NULL);
+ fail_if (xmalloc(this->reusable, this->capacity, size_t));
+ fail_if (xmalloc(this->values, this->capacity, size_t));
+ fail_if (xmalloc(this->next, this->capacity, size_t));
+ fail_if (xmalloc(this->previous, this->capacity, size_t));
memcpy(this->reusable, data, this->reuse_head * sizeof(ssize_t));
buf_next(data, ssize_t, this->reuse_head);
diff --git a/src/libmdsserver/macros.h b/src/libmdsserver/macros.h
index b39d750..672c0a3 100644
--- a/src/libmdsserver/macros.h
+++ b/src/libmdsserver/macros.h
@@ -339,6 +339,17 @@
/**
+ * `malloc` wrapper that returns whether the allocation was not successful
+ *
+ * @param var:type* The variable to which to assign the allocation
+ * @param bytes:size_t The number of bytes to allocate
+ * @return :int Evaluates to true if an only if the allocation failed
+ */
+#define xbmalloc(var, elements) \
+ ((var = malloc(elements)) == NULL)
+
+
+/**
* `calloc` wrapper that returns whether the allocation was not successful
*
* @param var:type* The variable to which to assign the allocation
@@ -351,6 +362,17 @@
/**
+ * `calloc` wrapper that returns whether the allocation was not successful
+ *
+ * @param var:type* The variable to which to assign the allocation
+ * @param bytes:size_t The number of bytes to allocate
+ * @return :int Evaluates to true if an only if the allocation failed
+ */
+#define xbcalloc(var, bytes) \
+ ((var = calloc(bytes, sizeof(char))) == NULL)
+
+
+/**
* `realloc` wrapper that returns whether the allocation was not successful
*
* @param var:type* The variable to which to assign the reallocation
@@ -365,7 +387,7 @@
/**
* `xrealloc` that stores the old variable
*
- * @param old:type* The variable to which to store with the old variable that needs
+ * @param old:type* The variable to which to store with the old variable that needs
* to be `free`:ed on failure, and set to `NULL` on success.
* @param var:type* The variable to which to assign the reallocation
* @param elements:size_t The number of elements to allocate
@@ -373,7 +395,21 @@
* @return :int Evaluates to true if an only if the allocation failed
*/
#define xxrealloc(old, var, elements, type) \
- (old = var, (xrealloc(var, elements, type) ? 1 : (old = NULL, 0)))
+ (old = var, (((var = realloc(var, (elements) * sizeof(type))) == NULL) ? 1 : (old = NULL, 0)))
+
+
+/**
+ * `xrealloc` that restores the variable on failure
+ *
+ * @param tmp:type* The variable to which to store with the old variable temporarily
+ * @param var:type* The variable to which to assign the reallocation
+ * @param elements:size_t The number of elements to allocate
+ * @param type The data type of the elements for which to create an allocation
+ * @return :int Evaluates to true if an only if the allocation failed
+ */
+#define yrealloc(tmp, var, elements, type) \
+ ((tmp = var, (var = realloc(var, (elements) * sizeof(type))) == NULL) \
+ ? (var = tmp, tmp = NULL, 1) : (tmp = NULL, 0))
/**
@@ -390,6 +426,17 @@
/**
+ * `strdup` wrapper that returns whether the allocation was not successful
+ *
+ * @param var:char* The variable to which to assign the duplicate
+ * @param original:const char* The string to duplicate
+ * @return :int Evaluates to true if an only if the allocation failed
+ */
+#define xstrdup(var, original) \
+ (original ? ((var = strdup(original)) == NULL) : (var = NULL, 0))
+
+
+/**
* Call `perror` if `errno` is non-zero and set `errno` to zero
*
* @param str:const char* The argument passed to `perror`
diff --git a/src/libmdsserver/util.c b/src/libmdsserver/util.c
index 123463c..211de32 100644
--- a/src/libmdsserver/util.c
+++ b/src/libmdsserver/util.c
@@ -135,8 +135,7 @@ void reexec_server(int argc, char** argv, int reexeced)
if (reexeced == 0)
{
*reexec_args_++ = *argv;
- *reexec_args_ = strdup("--re-exec");
- fail_if (*reexec_args_ == NULL);
+ fail_if (xstrdup(*reexec_args_, "--re-exec"));
for (i = 1; i < argc; i++)
reexec_args_[i] = argv[i];
}
diff --git a/src/mds-base.c b/src/mds-base.c
index a9a942b..f6b05ff 100644
--- a/src/mds-base.c
+++ b/src/mds-base.c
@@ -432,8 +432,7 @@ static int base_marshal(int reexec_fd)
state_n += marshal_server_size();
/* Allocate a buffer for all data. */
- state_buf = state_buf_ = malloc(state_n);
- fail_if (state_buf == NULL);
+ fail_if (xbmalloc(state_buf = state_buf_, state_n));
/* Marshal the state of the server. */
diff --git a/src/mds-kbdc/builtin-functions.c b/src/mds-kbdc/builtin-functions.c
index fbff16f..7cd13b7 100644
--- a/src/mds-kbdc/builtin-functions.c
+++ b/src/mds-kbdc/builtin-functions.c
@@ -29,24 +29,24 @@
/**
* Define useful data for built-in function with 2 parameters
*/
-#define define_2 \
- const char32_t* restrict a = *args++; \
- const char32_t* restrict b = *args++; \
- size_t an = string_length(a); \
- size_t bn = string_length(b); \
- size_t i, n = an > bn ? an : bn; \
- char32_t* restrict rc = malloc((n + 1) * sizeof(char32_t)); \
- fail_if (rc == NULL); \
+#define define_2 \
+ const char32_t* restrict a = *args++; \
+ const char32_t* restrict b = *args++; \
+ size_t an = string_length(a); \
+ size_t bn = string_length(b); \
+ size_t i, n = an > bn ? an : bn; \
+ char32_t* restrict rc; \
+ fail_if (xmalloc(rc, n + 1, char32_t)); \
rc[n] = -1
/**
* Define useful data for built-in function with 1 parameter
*/
-#define define_1 \
- const char32_t* restrict a = *args++; \
- size_t i, n = string_length(a); \
- char32_t* restrict rc = malloc((n + 1) * sizeof(char32_t)); \
- fail_if (rc == NULL); \
+#define define_1 \
+ const char32_t* restrict a = *args++; \
+ size_t i, n = string_length(a); \
+ char32_t* restrict rc; \
+ fail_if (xmalloc(rc, n + 1, char32_t)); \
rc[n] = -1
/**
diff --git a/src/mds-kbdc/callables.c b/src/mds-kbdc/callables.c
index 4c984c1..f27f94f 100644
--- a/src/mds-kbdc/callables.c
+++ b/src/mds-kbdc/callables.c
@@ -100,27 +100,25 @@ void callables_terminate(void)
int callables_set(const char* restrict name, size_t arg_count, mds_kbdc_tree_t* restrict callable,
mds_kbdc_include_stack_t* restrict callable_include_stack)
{
-#define yrealloc(var, elements, type) \
- (new_##var = realloc(var, (elements) * sizeof(type)), \
- (new_##var == NULL) ? -1 : (var = new_##var, new_##var = NULL, 0))
+#define _yrealloc(var, elements, type) (yrealloc(tmp_##var, var, elements, type))
char* dupname = NULL;
- char*** new_names = NULL;
- size_t** new_callables = NULL;
- size_t* new_bucket_sizes = NULL;
+ char*** tmp_names = NULL;
+ size_t** tmp_callables = NULL;
+ size_t* tmp_bucket_sizes = NULL;
char** old_names = NULL;
size_t* old_callables = NULL;
- mds_kbdc_tree_t** new_callable_list = NULL;
- mds_kbdc_include_stack_t** new_callable_include_stack_list = NULL;
+ mds_kbdc_tree_t** tmp_callable_list = NULL;
+ mds_kbdc_include_stack_t** tmp_callable_include_stack_list = NULL;
int saved_errno;
- fail_if (dupname = strdup(name), dupname == NULL);
+ fail_if (xstrdup(dupname, name));
if (arg_count >= buckets)
{
- fail_if (yrealloc(names, arg_count + 1, char**));
- fail_if (yrealloc(callables, arg_count + 1, size_t*));
- fail_if (yrealloc(bucket_sizes, arg_count + 1, size_t));
+ fail_if (_yrealloc(names, arg_count + 1, char**));
+ fail_if (_yrealloc(callables, arg_count + 1, size_t*));
+ fail_if (_yrealloc(bucket_sizes, arg_count + 1, size_t));
memset(names + buckets, 0, (arg_count + 1 - buckets) * sizeof(char**));
memset(callables + buckets, 0, (arg_count + 1 - buckets) * sizeof(size_t*));
memset(bucket_sizes + buckets, 0, (arg_count + 1 - buckets) * sizeof(size_t));
@@ -134,8 +132,8 @@ int callables_set(const char* restrict name, size_t arg_count, mds_kbdc_tree_t*
callables[arg_count][bucket_sizes[arg_count]] = list_ptr;
bucket_sizes[arg_count]++;
- fail_if (yrealloc(callable_list, list_ptr + 1, mds_kbdc_tree_t*));
- fail_if (yrealloc(callable_include_stack_list, list_ptr + 1, mds_kbdc_include_stack_t*));
+ fail_if (_yrealloc(callable_list, list_ptr + 1, mds_kbdc_tree_t*));
+ fail_if (_yrealloc(callable_include_stack_list, list_ptr + 1, mds_kbdc_include_stack_t*));
callable_list[list_ptr] = callable;
callable_include_stack_list[list_ptr] = callable_include_stack;
@@ -145,17 +143,12 @@ int callables_set(const char* restrict name, size_t arg_count, mds_kbdc_tree_t*
fail:
saved_errno = errno;
free(dupname);
- free(new_names);
- free(new_callables);
- free(new_bucket_sizes);
- free(new_callable_list);
- free(new_callable_include_stack_list);
if (old_names)
names[arg_count] = old_names;
if (old_callables)
callables[arg_count] = old_callables;
return errno = saved_errno, -1;
-#undef yrealloc
+#undef _yrealloc
}
diff --git a/src/mds-kbdc/compile-layout.c b/src/mds-kbdc/compile-layout.c
index 574f818..011d2d0 100644
--- a/src/mds-kbdc/compile-layout.c
+++ b/src/mds-kbdc/compile-layout.c
@@ -633,20 +633,20 @@ static char32_t* parse_escape(mds_kbdc_tree_t* restrict tree, const char* restri
#define R(LOWER, UPPER) (((LOWER) <= c) && (c <= (UPPER)))
#define CR(COND, LOWER, UPPER) ((*escape == (COND)) && R(LOWER, UPPER))
#define VARIABLE (int)(raw - raw_) - (c == '.'), raw_
-#define RETURN_ERROR(...) \
- do \
- { \
- NEW_ERROR(__VA_ARGS__); \
- error->start = lineoff; \
- error->end = lineoff + (size_t)(raw - raw_); \
- tree->processed = PROCESS_LEVEL; \
- *escape = 0; \
- if (rc) \
- goto done; \
- fail_if (rc = malloc(sizeof(char32_t)), rc == NULL); \
- *rc = -1; \
- goto done; \
- } \
+#define RETURN_ERROR(...) \
+ do \
+ { \
+ NEW_ERROR(__VA_ARGS__); \
+ error->start = lineoff; \
+ error->end = lineoff + (size_t)(raw - raw_); \
+ tree->processed = PROCESS_LEVEL; \
+ *escape = 0; \
+ if (rc) \
+ goto done; \
+ fail_if (xmalloc(rc, 1, char32_t)); \
+ *rc = -1; \
+ goto done; \
+ } \
while (0)
const char* restrict raw_ = raw++;
@@ -900,7 +900,7 @@ static char32_t* parse_unquoted_string(mds_kbdc_tree_t* restrict tree, const cha
else CHAR_ERROR(tree, ERROR, "stray ‘%c’", c);
done:
- fail_if (rc = malloc(2 * sizeof(char32_t)), rc == NULL);
+ fail_if (xmalloc(rc, 2, char32_t));
return rc[0] = buf, rc[1] = -1, rc;
fail:
diff --git a/src/mds-kbdc/include-stack.c b/src/mds-kbdc/include-stack.c
index d8c4547..b34b57b 100644
--- a/src/mds-kbdc/include-stack.c
+++ b/src/mds-kbdc/include-stack.c
@@ -220,15 +220,13 @@ mds_kbdc_include_stack_t* mds_kbdc_include_stack_save(void)
*/
int mds_kbdc_include_stack_restore(mds_kbdc_include_stack_t* restrict stack)
{
- const mds_kbdc_tree_include_t** new;
+ const mds_kbdc_tree_include_t** tmp;
latest_save = stack;
if (stack->ptr > includes_size)
{
- new = realloc(includes, stack->ptr * sizeof(const mds_kbdc_tree_include_t*));
- fail_if (new == NULL);
- includes = new;
+ fail_if (yrealloc(tmp, includes, stack->ptr, const mds_kbdc_tree_include_t*));
includes_size = stack->ptr;
}
diff --git a/src/mds-kbdc/make-tree.c b/src/mds-kbdc/make-tree.c
index 960fe22..b2273e4 100644
--- a/src/mds-kbdc/make-tree.c
+++ b/src/mds-kbdc/make-tree.c
@@ -441,8 +441,7 @@ static int get_pathname(const char* restrict filename)
fail_if (errno != ENOENT);
saved_errno = errno;
fail_if (cwd = curpath(), cwd == NULL);
- result->pathname = strdup(filename);
- fail_if (result->pathname == NULL);
+ fail_if (xstrdup(result->pathname, filename));
NEW_ERROR_(result, ERROR, 0, 0, 0, 0, 1, "no such file or directory in ‘%s’", cwd);
free(cwd);
return 0;
@@ -453,8 +452,7 @@ static int get_pathname(const char* restrict filename)
{
saved_errno = errno;
NEW_ERROR_(result, ERROR, 0, 0, 0, 0, 0, NULL);
- error->description = strdup(strerror(saved_errno));
- fail_if (error->description == NULL);
+ fail_if (xstrdup(error->description, strerror(saved_errno)));
return 0;
}
@@ -649,7 +647,7 @@ static int names_1(char** restrict var)
end = name_end;
prev_end_char = *end;
*end = '\0';
- fail_if ((*var = strdup(line)) == NULL);
+ fail_if (xstrdup(*var, line));
}
return 0;
@@ -699,7 +697,7 @@ static int chars(char** restrict var)
else quote = (c == '"');
}
prev_end_char = *arg_end, *arg_end = '\0', end = arg_end;
- fail_if ((*var = strdup(line)) == NULL);
+ fail_if (xstrdup(*var, line));
line = end;
}
@@ -837,13 +835,13 @@ static int keys(mds_kbdc_tree_t** restrict var)
{
NEW_SUBNODE(keys, KEYS);
*var = (mds_kbdc_tree_t*)subnode;
- fail_if ((subnode->keys = strdup(line)) == NULL);
+ fail_if (xstrdup(subnode->keys, line));
}
else
{
NEW_SUBNODE(string, STRING);
*var = (mds_kbdc_tree_t*)subnode;
- fail_if ((subnode->string = strdup(line)) == NULL);
+ fail_if (xstrdup(subnode->string, line));
}
line = end;
@@ -891,7 +889,7 @@ static int pure_keys(char** restrict var)
else if (IS_END(c) && !triangle) { arg_end--; break; }
}
prev_end_char = *arg_end, *arg_end = '\0';
- fail_if ((*var = strdup(line)) == NULL);
+ fail_if (xstrdup(*var, line));
end = arg_end, line = end;
return 0;
diff --git a/src/mds-kbdc/parsed.c b/src/mds-kbdc/parsed.c
index 8ab483b..f5fc311 100644
--- a/src/mds-kbdc/parsed.c
+++ b/src/mds-kbdc/parsed.c
@@ -138,15 +138,14 @@ mds_kbdc_parse_error_t* mds_kbdc_parsed_new_error(mds_kbdc_parsed_t* restrict th
if (this->severest_error_level < severity)
this->severest_error_level = severity;
- fail_if ((error->pathname = strdup(this->pathname)) == NULL);
+ fail_if (xstrdup(error->pathname, this->pathname));
if ((error->error_is_in_file = error_is_in_file))
{
error->line = line;
error->start = start;
error->end = end;
- error->code = strdup(this->source_code->real_lines[line]);
- fail_if (error->code == NULL);
+ fail_if (xstrdup(error->code, this->source_code->real_lines[line]));
}
return error;
diff --git a/src/mds-kbdc/paths.c b/src/mds-kbdc/paths.c
index e294020..031083e 100644
--- a/src/mds-kbdc/paths.c
+++ b/src/mds-kbdc/paths.c
@@ -74,7 +74,7 @@ char* abspath(const char* path)
if (*path == '/')
{
- fail_if (buf = strdup(path), buf == NULL);
+ fail_if (xstrdup(buf, path));
return buf;
}
diff --git a/src/mds-kbdc/process-includes.c b/src/mds-kbdc/process-includes.c
index 2faaf3f..cf07f56 100644
--- a/src/mds-kbdc/process-includes.c
+++ b/src/mds-kbdc/process-includes.c
@@ -169,7 +169,7 @@ static int process_include(mds_kbdc_tree_include_t* restrict tree)
mds_kbdc_parsed_initialise(&subresult);
/* Get dirname of current file. */
- fail_if ((dirname = strdup(result->pathname)) == NULL);
+ fail_if (xstrdup(dirname, result->pathname));
*(strrchr(dirname, '/')) = '\0';
/* Get the current working directory. */
diff --git a/src/mds-kbdc/raw-data.c b/src/mds-kbdc/raw-data.c
index 52bec82..cf48486 100644
--- a/src/mds-kbdc/raw-data.c
+++ b/src/mds-kbdc/raw-data.c
@@ -489,8 +489,7 @@ char* parse_raw_string(const char* restrict string)
* but when parsed it generateds 2 bytes in UTF-8, and their
* is not code point whose UTF-8 encoding is longer than its
* hexadecimal representation. */
- p = rc = malloc(strlen(string) * sizeof(char));
- fail_if (rc == NULL);
+ fail_if (xmalloc(p = rc, strlen(string), char));
while ((c = *string++))
if (r(escape == 8, '0', '7')) buf = (buf << 3) | (c & 15);
diff --git a/src/mds-kbdc/tree.c b/src/mds-kbdc/tree.c
index 6ee98c1..4e6fef3 100644
--- a/src/mds-kbdc/tree.c
+++ b/src/mds-kbdc/tree.c
@@ -254,7 +254,7 @@ void mds_kbdc_tree_free(mds_kbdc_tree_t* restrict this)
*
* @param member:identifer The member in the tree to duplicate
*/
-#define S(member) fail_if (t->member && (n->member = strdup(t->member), n->member == NULL))
+#define S(member) fail_if (t->member && xstrdup(n->member, t->member))
/**
diff --git a/src/mds-registry/reexec.c b/src/mds-registry/reexec.c
index 6f6510e..f1e458c 100644
--- a/src/mds-registry/reexec.c
+++ b/src/mds-registry/reexec.c
@@ -157,11 +157,11 @@ int unmarshal_server(char* state_buf)
for (i = 0; i < n; i++)
{
stage = 1;
- fail_if ((command = strdup(state_buf)) == NULL);
+ fail_if (xstrdup(command, state_buf));
state_buf += strlen(command) + 1;
stage = 2;
- fail_if ((list = malloc(sizeof(client_list_t))) == NULL);
+ fail_if (xmalloc(list, 1, client_list_t));
buf_get_next(state_buf, size_t, m);
stage = 3;
fail_if (client_list_unmarshal(list, state_buf));
@@ -183,7 +183,7 @@ int unmarshal_server(char* state_buf)
foreach_linked_list_node (slave_list, node)
{
stage = 5;
- fail_if ((slave = malloc(sizeof(slave_t))) == NULL);
+ fail_if (xmalloc(slave, 1, slave_t));
stage = 6;
fail_if ((n = slave_unmarshal(slave, state_buf)) == 0);
state_buf += n / sizeof(char);
diff --git a/src/mds-registry/registry.c b/src/mds-registry/registry.c
index f853f93..b13c7b4 100644
--- a/src/mds-registry/registry.c
+++ b/src/mds-registry/registry.c
@@ -139,11 +139,11 @@ static int registry_action_add(int has_key, char* command, size_t command_key, u
/* If the protocol is not already in the table. */
/* Allocate list of servers for the protocol. */
- client_list_t* list = malloc(sizeof(client_list_t));
- void* address = list;
- fail_if (list == NULL);
+ client_list_t* list;
+ void* address;
+ fail_if (xmalloc(address = list, 1, client_list_t));
/* Duplicate the protocol name so it can be accessed later. */
- if ((command = strdup(command)) == NULL)
+ if (xstrdup(command, command))
{
saved_errno = errno, free(list), errno = saved_errno;
fail_if (1);
@@ -227,7 +227,7 @@ static int registry_action_act(char* command, int action, uint64_t client, hash_
else if ((action == 0) && !has_key)
{
/* Add protocol to wait set of not present in the protocol table. */
- fail_if ((command = strdup(command)) == NULL);
+ fail_if (xstrdup(command, command));
command_key = (size_t)(void*)command;
if (hash_table_put(wait_set, command_key, 1) == 0)
if (errno)
diff --git a/src/mds-registry/slave.c b/src/mds-registry/slave.c
index ef46963..5e496f5 100644
--- a/src/mds-registry/slave.c
+++ b/src/mds-registry/slave.c
@@ -283,8 +283,8 @@ slave_t* slave_create(hash_table_t* restrict wait_set, const char* restrict recv
rc->wait_set = wait_set;
rc->client = parse_client_id(recv_client_id);
- fail_if ((rc->client_id = strdup(recv_client_id)) == NULL);
- fail_if ((rc->message_id = strdup(recv_message_id)) == NULL);
+ fail_if (xstrdup(rc->client_id, recv_client_id));
+ fail_if (xstrdup(rc->message_id, recv_message_id));
return rc;
@@ -432,16 +432,16 @@ size_t slave_unmarshal(slave_t* restrict this, char* restrict data)
buf_get_next(data, long, this->dethklok.tv_nsec);
n = (strlen((char*)data) + 1) * sizeof(char);
- fail_if ((this->client_id = malloc(n)) == NULL);
+ fail_if (xbmalloc(this->client_id, n));
memcpy(this->client_id, data, n);
data += n, rc += n;
n = (strlen((char*)data) + 1) * sizeof(char);
- fail_if ((this->message_id = malloc(n)) == NULL);
+ fail_if (xbmalloc(this->message_id, n));
memcpy(this->message_id, data, n);
data += n, rc += n;
- fail_if ((this->wait_set = malloc(sizeof(hash_table_t))) == NULL);
+ fail_if (xmalloc(this->wait_set, 1, hash_table_t));
fail_if (hash_table_create(this->wait_set));
buf_get_next(data, size_t, m);
@@ -449,7 +449,7 @@ size_t slave_unmarshal(slave_t* restrict this, char* restrict data)
while (m--)
{
n = (strlen((char*)data) + 1) * sizeof(char);
- fail_if ((protocol = malloc(n)) == NULL);
+ fail_if (xbmalloc(protocol, n));
memcpy(protocol, data, n);
data += n, rc += n;
diff --git a/src/mds-respawn.c b/src/mds-respawn.c
index b95f40e..b471b19 100644
--- a/src/mds-respawn.c
+++ b/src/mds-respawn.c
@@ -292,7 +292,7 @@ int postinitialise_server(void)
if (commands_args[i] == NULL)
j++;
else if (strequals(commands_args[i], "--initial-spawn"))
- fail_if ((commands_args[i] = strdup("--respawn")) == NULL);
+ fail_if (xstrdup(commands_args[i], "--respawn"));
/* Respawn dead and dead and buried servers.*/
diff --git a/src/mds-server/interception-condition.c b/src/mds-server/interception-condition.c
index cfe5d0c..92190af 100644
--- a/src/mds-server/interception-condition.c
+++ b/src/mds-server/interception-condition.c
@@ -71,7 +71,7 @@ size_t interception_condition_unmarshal(interception_condition_t* restrict this,
buf_get_next(data, int64_t, this->priority);
buf_get_next(data, int, this->modifying);
n = (strlen(data) + 1) * sizeof(char);
- fail_if ((this->condition = malloc(n)) == NULL);
+ fail_if (xbmalloc(this->condition, n));
memcpy(this->condition, data, n);
return sizeof(size_t) + sizeof(int64_t) + 2 * sizeof(int) + n;
fail:
diff --git a/src/mds-server/interceptors.c b/src/mds-server/interceptors.c
index 8a24e33..c1dafec 100644
--- a/src/mds-server/interceptors.c
+++ b/src/mds-server/interceptors.c
@@ -140,7 +140,7 @@ void add_intercept_condition(client_t* client, char* condition, int64_t priority
else
{
/* Duplicate condition string. */
- fail_if ((condition = strdup(condition)) == NULL);
+ fail_if (xstrdup(condition, condition));
/* Grow the interception condition list. */
fail_if (xrealloc(conds, n + 1, interception_condition_t));
diff --git a/src/mds-server/mds-server.c b/src/mds-server/mds-server.c
index fabdffa..29caee3 100644
--- a/src/mds-server/mds-server.c
+++ b/src/mds-server/mds-server.c
@@ -429,13 +429,13 @@ void queue_message_multicast(char* message, size_t length, client_t* sender)
char* colon = strchr(msg, ':');
*end = '\0';
- if ((header_values[i] = strdup(msg)) == NULL)
+ if (xstrdup(header_values[i], msg))
{
header_count = i;
fail_if (1);
}
*colon = '\0';
- if ((headers[i] = strdup(msg)) == NULL)
+ if (xstrdup(headers[i], msg))
{
saved_errno = errno, free(headers[i]), errno = saved_errno;
header_count = i;
diff --git a/src/mds-server/receiving.c b/src/mds-server/receiving.c
index 8571944..bc22fe2 100644
--- a/src/mds-server/receiving.c
+++ b/src/mds-server/receiving.c
@@ -82,10 +82,7 @@ static int modifying_notify(client_t* client, mds_message_t message, uint64_t mo
memcpy(multicast->payload, message.payload, message.payload_size * sizeof(char));
fail_if (xmalloc(multicast->headers, message.header_count, char*));
for (i = 0; i < message.header_count; i++, multicast->header_count++)
- {
- multicast->headers[i] = strdup(message.headers[i]);
- fail_if (multicast->headers[i] == NULL);
- }
+ fail_if (xstrdup(multicast->headers[i], message.headers[i]));
done:
pthread_mutex_unlock(&(modify_mutex));
with_mutex (client->modify_mutex, pthread_cond_signal(&(client->modify_cond)););
@@ -199,8 +196,7 @@ static int assign_and_send_id(client_t* client, const char* message_id)
n = strlen(msgbuf);
/* Multicast the reply. */
- msgbuf_ = strdup(msgbuf);
- fail_if (msgbuf_ == NULL);
+ fail_if (xstrdup(msgbuf_, msgbuf));
queue_message_multicast(msgbuf_, n, client);
/* Queue message to be sent when this function returns.
@@ -317,7 +313,7 @@ int message_received(client_t* client)
/* Multicast the message. */
n = mds_message_compose_size(&message);
- fail_if ((msgbuf = malloc(n)) == NULL);
+ fail_if (xbmalloc(msgbuf, n));
mds_message_compose(&message, msgbuf);
queue_message_multicast(msgbuf, n / sizeof(char), client);
msgbuf = NULL;
diff --git a/src/mds.c b/src/mds.c
index 29b1d94..88b4b96 100644
--- a/src/mds.c
+++ b/src/mds.c
@@ -324,10 +324,10 @@ int spawn_and_respawn_server(int fd)
pid_t pid;
int status;
- child_args[0] = strdup(master_server);
+ fail_if (xstrdup(child_args[0], master_server));
for (i = 1; i < argc; i++)
child_args[i] = argv[i];
- child_args[argc + 0] = strdup("--initial-spawn");
+ fail_if (xstrdup(child_args[argc + 0], "--initial-spawn"));
xsnprintf(fdstr, "--socket-fd=%i", fd);
child_args[argc + 1] = fdstr;
child_args[argc + 2] = NULL;
@@ -401,8 +401,7 @@ int spawn_and_respawn_server(int fd)
{
first_spawn = 0;
free(child_args[argc + 0]);
- child_args[argc + 0] = strdup("--respawn");
- fail_if (child_args[argc + 0] == NULL);
+ fail_if (xstrdup(child_args[argc + 0], "--respawn"));
}
goto respawn;