aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-12-08 19:28:41 +0100
committerMattias Andrée <maandree@operamail.com>2014-12-08 19:28:41 +0100
commit718a400d599f3df3a64c2c0659a48fb9d22b6105 (patch)
tree48041ab3edec8580781fc37c201f6fb7e6794d51
parentno more goto fail (diff)
downloadmds-718a400d599f3df3a64c2c0659a48fb9d22b6105.tar.gz
mds-718a400d599f3df3a64c2c0659a48fb9d22b6105.tar.bz2
mds-718a400d599f3df3a64c2c0659a48fb9d22b6105.tar.xz
m + make sure we never lose errno
Signed-off-by: Mattias Andrée <maandree@operamail.com>
-rw-r--r--src/libmdsserver/client-list.c4
-rw-r--r--src/libmdsserver/linked-list.c8
-rw-r--r--src/mds-registry/reexec.c18
-rw-r--r--src/mds-registry/registry.c9
-rw-r--r--src/mds-registry/slave.c7
-rw-r--r--src/mds-server/mds-server.c3
-rw-r--r--src/mds-server/slavery.c8
-rw-r--r--src/mds.c4
8 files changed, 31 insertions, 30 deletions
diff --git a/src/libmdsserver/client-list.c b/src/libmdsserver/client-list.c
index 5562747..1bcaa72 100644
--- a/src/libmdsserver/client-list.c
+++ b/src/libmdsserver/client-list.c
@@ -101,6 +101,7 @@ int client_list_clone(const client_list_t* restrict this, client_list_t* restric
{
size_t n = this->capacity * sizeof(uint64_t);
uint64_t* restrict new_clients = NULL;
+ int saved_errno;
out->clients = NULL;
@@ -116,8 +117,9 @@ int client_list_clone(const client_list_t* restrict this, client_list_t* restric
return 0;
pfail:
+ saved_errno = errno;
free(new_clients);
- return -1;
+ return errno = saved_errno, -1;
}
diff --git a/src/libmdsserver/linked-list.c b/src/libmdsserver/linked-list.c
index 83f7711..d17ba8b 100644
--- a/src/libmdsserver/linked-list.c
+++ b/src/libmdsserver/linked-list.c
@@ -116,6 +116,7 @@ int linked_list_clone(const linked_list_t* restrict this, linked_list_t* restric
ssize_t* restrict new_next = NULL;
ssize_t* restrict new_previous = NULL;
ssize_t* restrict new_reusable;
+ int saved_errno;
out->values = NULL;
out->next = NULL;
@@ -145,10 +146,11 @@ int linked_list_clone(const linked_list_t* restrict this, linked_list_t* restric
return 0;
pfail:
+ saved_errno = errno;
free(new_values);
free(new_next);
free(new_previous);
- return -1;
+ return errno = saved_errno, -1;
}
@@ -177,6 +179,7 @@ int linked_list_pack(linked_list_t* restrict this)
size_t i = 0;
ssize_t node;
size_t* restrict vals;
+ int saved_errno;
if (xmalloc(vals, cap, size_t))
return -1;
@@ -219,10 +222,11 @@ int linked_list_pack(linked_list_t* restrict this)
return 0;
pfail:
+ saved_errno = errno;
free(vals);
free(new_next);
free(new_previous);
- return -1;
+ return errno = saved_errno, -1;
}
diff --git a/src/mds-registry/reexec.c b/src/mds-registry/reexec.c
index 6247e18..6b36cc8 100644
--- a/src/mds-registry/reexec.c
+++ b/src/mds-registry/reexec.c
@@ -202,20 +202,10 @@ int unmarshal_server(char* state_buf)
mds_message_destroy(&received);
if (stage >= 1)
hash_table_destroy(&reg_table, (free_func*)reg_table_free_key, (free_func*)reg_table_free_value);
- if (stage >= 2)
- free(command);
- if (stage >= 3)
- {
- client_list_destroy(list);
- free(list);
- }
- if (stage >= 5)
- linked_list_destroy(&slave_list);
- if (stage >= 6)
- {
- slave_destroy(slave);
- free(slave);
- }
+ if (stage >= 2) free(command);
+ if (stage >= 3) client_list_destroy(list), free(list);
+ if (stage >= 5) linked_list_destroy(&slave_list);
+ if (stage >= 6) slave_destroy(slave), free(slave);
abort();
return -1;
}
diff --git a/src/mds-registry/registry.c b/src/mds-registry/registry.c
index b8a24ac..918b137 100644
--- a/src/mds-registry/registry.c
+++ b/src/mds-registry/registry.c
@@ -125,6 +125,8 @@ static int handle_close_message(void)
*/
static int registry_action_add(int has_key, char* command, size_t command_key, uint64_t client)
{
+ int saved_errno;
+
if (has_key)
{
/* Add server to protocol if the protocol is already in the table. */
@@ -143,7 +145,7 @@ static int registry_action_add(int has_key, char* command, size_t command_key, u
/* Duplicate the protocol name so it can be accessed later. */
if ((command = strdup(command)) == NULL)
{
- free(list);
+ saved_errno = errno, free(list), errno = saved_errno;
fail_if (1);
}
/* Create list of servers, add server to list and add the protocol to the table. */
@@ -152,9 +154,11 @@ static int registry_action_add(int has_key, char* command, size_t command_key, u
client_list_add(list, client) ||
(hash_table_put(&reg_table, command_key, (size_t)address) == 0))
{
+ saved_errno = errno;
client_list_destroy(list);
free(list);
free(command);
+ errno = saved_errno;
fail_if (1);
}
}
@@ -210,6 +214,7 @@ static int registry_action_act(char* command, int action, uint64_t client, hash_
{
size_t command_key = (size_t)(void*)command;
int has_key = hash_table_contains_key(&reg_table, command_key);
+ int saved_errno;
if (action == 1)
{
@@ -228,7 +233,7 @@ static int registry_action_act(char* command, int action, uint64_t client, hash_
if (hash_table_put(wait_set, command_key, 1) == 0)
if (errno)
{
- free(command);
+ saved_errno = errno, free(command), errno = saved_errno;
fail_if (1);
}
}
diff --git a/src/mds-registry/slave.c b/src/mds-registry/slave.c
index 8e29f17..54774e2 100644
--- a/src/mds-registry/slave.c
+++ b/src/mds-registry/slave.c
@@ -271,6 +271,7 @@ int advance_slaves(char* command)
slave_t* slave_create(hash_table_t* restrict wait_set, const char* restrict recv_client_id, const char* restrict recv_message_id)
{
slave_t* restrict rc = NULL;
+ int saved_errno;
fail_if (xmalloc(rc, 1, slave_t));
@@ -284,9 +285,9 @@ slave_t* slave_create(hash_table_t* restrict wait_set, const char* restrict recv
return rc;
pfail:
- slave_destroy(rc);
- free(rc);
- return NULL;
+ saved_errno = errno;
+ slave_destroy(rc), free(rc);
+ return errno = saved_errno, NULL;
}
diff --git a/src/mds-server/mds-server.c b/src/mds-server/mds-server.c
index 499ba96..abfc871 100644
--- a/src/mds-server/mds-server.c
+++ b/src/mds-server/mds-server.c
@@ -403,6 +403,7 @@ void queue_message_multicast(char* message, size_t length, client_t* sender)
uint64_t modify_id;
char modify_id_header[13 + 3 * sizeof(uint64_t)];
void* new_buf;
+ int saved_errno;
/* Count the number of headers. */
for (i = 0; i < n; i++)
@@ -440,7 +441,7 @@ void queue_message_multicast(char* message, size_t length, client_t* sender)
*colon = '\0';
if ((headers[i] = strdup(msg)) == NULL)
{
- free(headers[i]);
+ saved_errno = errno, free(headers[i]), errno = saved_errno;
header_count = i;
fail_if (1);
}
diff --git a/src/mds-server/slavery.c b/src/mds-server/slavery.c
index 283251a..a951f99 100644
--- a/src/mds-server/slavery.c
+++ b/src/mds-server/slavery.c
@@ -101,9 +101,8 @@ int create_slave(pthread_t* thread_slot, int slave_fd)
client_t* initialise_client(int client_fd)
{
ssize_t entry = LINKED_LIST_UNUSED;
- int locked = 0;
client_t* information;
- int errno_;
+ int locked = 0, saved_errno;
size_t tmp;
/* Create information table. */
@@ -132,7 +131,7 @@ client_t* initialise_client(int client_fd)
pfail:
- errno_ = errno;
+ saved_errno = errno;
if (locked)
pthread_mutex_unlock(&slave_mutex);
free(information);
@@ -140,7 +139,6 @@ client_t* initialise_client(int client_fd)
{
with_mutex (slave_mutex, linked_list_remove(&client_list, entry););
}
- errno = errno_;
- return NULL;
+ return saved_errno = errno, NULL;
}
diff --git a/src/mds.c b/src/mds.c
index 23c6bac..1c0f002 100644
--- a/src/mds.c
+++ b/src/mds.c
@@ -517,11 +517,11 @@ int unlink_recursive(const char* pathname)
/* Check that we could examine the directory. */
if (dir == NULL)
{
- int errno_ = errno;
+ int saved_errno = errno;
struct stat _attr;
if (stat(pathname, &_attr) < 0)
return 0; /* Directory does not exist. */
- errno = errno_;
+ errno = saved_errno;
fail_if (1);
}