mirror of
https://salsa.debian.org/ha-team/libqb
synced 2026-08-10 07:35:34 +00:00
Improve the error handling esp. after failed malloc's
Reviewed-by: Angus Salkeld <asalkeld@redhat.com>
This commit is contained in:
parent
a44df811a0
commit
fcd96fc8e0
@ -275,6 +275,9 @@ hashtable_notify_add(qb_map_t * m, const char *key,
|
||||
}
|
||||
|
||||
f = malloc(sizeof(struct qb_map_notifier));
|
||||
if (f == NULL) {
|
||||
return -errno;
|
||||
}
|
||||
f->events = events;
|
||||
f->user_data = user_data;
|
||||
f->callback = fn;
|
||||
@ -328,6 +331,9 @@ static qb_map_iter_t *
|
||||
hashtable_iter_create(struct qb_map *map, const char *prefix)
|
||||
{
|
||||
struct hashtable_iter *i = malloc(sizeof(struct hashtable_iter));
|
||||
if (i == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
i->i.m = map;
|
||||
i->node = NULL;
|
||||
i->bucket = 0;
|
||||
|
||||
@ -278,7 +278,7 @@ qb_ipcc_smq_connect(struct qb_ipcc_connection *c,
|
||||
if (c->response.u.smq.q == -1) {
|
||||
res = -errno;
|
||||
perror("msgget:RESPONSE");
|
||||
goto cleanup;
|
||||
goto cleanup_request;
|
||||
}
|
||||
|
||||
memcpy(&c->event.u.smq.key, response->event, sizeof(uint32_t));
|
||||
@ -286,9 +286,14 @@ qb_ipcc_smq_connect(struct qb_ipcc_connection *c,
|
||||
if (c->event.u.smq.q == -1) {
|
||||
res = -errno;
|
||||
perror("msgget:EVENT");
|
||||
goto cleanup;
|
||||
goto cleanup_request_response;
|
||||
}
|
||||
return 0;
|
||||
|
||||
cleanup_request_response:
|
||||
msgctl(c->response.u.smq.q, IPC_RMID, NULL);
|
||||
cleanup_request:
|
||||
msgctl(c->request.u.smq.q, IPC_RMID, NULL);
|
||||
cleanup:
|
||||
return res;
|
||||
}
|
||||
@ -346,10 +351,10 @@ qb_ipcs_smq_connect(struct qb_ipcs_service *s,
|
||||
r->hdr.error = 0;
|
||||
return 0;
|
||||
|
||||
cleanup_request:
|
||||
msgctl(c->request.u.smq.q, IPC_RMID, NULL);
|
||||
cleanup_request_response:
|
||||
msgctl(c->response.u.smq.q, IPC_RMID, NULL);
|
||||
cleanup_request:
|
||||
msgctl(c->request.u.smq.q, IPC_RMID, NULL);
|
||||
|
||||
cleanup:
|
||||
r->hdr.error = res;
|
||||
|
||||
@ -149,6 +149,9 @@ qb_log_dcs_get(int32_t * newly_created,
|
||||
|
||||
if (cs == NULL) {
|
||||
csl = calloc(1, sizeof(struct callsite_list));
|
||||
if (csl == NULL) {
|
||||
goto cleanup;
|
||||
}
|
||||
csl->cs = _log_dcs_new_cs(function, filename, format,
|
||||
priority, lineno, tags);
|
||||
csl->next = NULL;
|
||||
@ -157,6 +160,7 @@ qb_log_dcs_get(int32_t * newly_created,
|
||||
*newly_created = QB_TRUE;
|
||||
}
|
||||
}
|
||||
cleanup:
|
||||
(void)qb_thread_unlock(arr_next_lock);
|
||||
|
||||
return cs;
|
||||
|
||||
@ -908,6 +908,9 @@ qb_loop_signals_create(struct qb_loop *l)
|
||||
struct qb_poll_entry *pe;
|
||||
struct qb_signal_source *s = calloc(1, sizeof(struct qb_signal_source));
|
||||
|
||||
if (s == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
s->s.l = l;
|
||||
s->s.dispatch_and_take_back = _signal_dispatch_and_take_back_;
|
||||
s->s.poll = NULL;
|
||||
@ -980,6 +983,9 @@ _qb_signal_add_to_jobs_(struct qb_loop *l, struct qb_poll_entry *pe)
|
||||
sig = (struct qb_loop_sig *)item;
|
||||
if (sig->signal == the_signal) {
|
||||
new_sig_job = calloc(1, sizeof(struct qb_loop_sig));
|
||||
if (new_sig_job == NULL) {
|
||||
return jobs_added;
|
||||
}
|
||||
memcpy(new_sig_job, sig, sizeof(struct qb_loop_sig));
|
||||
|
||||
new_sig_job->cloned_from = sig;
|
||||
@ -1043,6 +1049,9 @@ qb_loop_signal_add(qb_loop_t * l,
|
||||
}
|
||||
s = (struct qb_signal_source *)l->signal_source;
|
||||
sig = calloc(1, sizeof(struct qb_loop_sig));
|
||||
if (sig == NULL) {
|
||||
return -errno;
|
||||
}
|
||||
|
||||
sig->dispatch_fn = dispatch_fn;
|
||||
sig->p = p;
|
||||
|
||||
@ -603,7 +603,7 @@ qb_rb_create_from_file(int32_t fd, uint32_t flags)
|
||||
}
|
||||
rb->shared_hdr = calloc(1, sizeof(struct qb_ringbuffer_shared_s));
|
||||
if (rb->shared_hdr == NULL) {
|
||||
goto cleanup_fail;
|
||||
goto cleanup_fail2;
|
||||
}
|
||||
|
||||
rb->flags = flags;
|
||||
@ -651,6 +651,7 @@ qb_rb_create_from_file(int32_t fd, uint32_t flags)
|
||||
|
||||
cleanup_fail:
|
||||
free(rb->shared_hdr);
|
||||
cleanup_fail2:
|
||||
free(rb);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -248,6 +248,9 @@ skiplist_notify_add(qb_map_t * m, const char *key,
|
||||
}
|
||||
if (n) {
|
||||
f = malloc(sizeof(struct qb_map_notifier));
|
||||
if (f == NULL) {
|
||||
return -errno;
|
||||
}
|
||||
f->events = events;
|
||||
f->user_data = user_data;
|
||||
f->callback = fn;
|
||||
@ -422,6 +425,9 @@ skiplist_iter_create(struct qb_map *map, const char *prefix)
|
||||
{
|
||||
struct skiplist_iter *i = malloc(sizeof(struct skiplist_iter));
|
||||
struct skiplist *list = (struct skiplist *)map;
|
||||
if (i == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
i->i.m = map;
|
||||
i->n = list->header;
|
||||
i->n->refcount++;
|
||||
|
||||
17
lib/trie.c
17
lib/trie.c
@ -159,11 +159,19 @@ trie_new_node(struct trie *t, struct trie_node *parent)
|
||||
{
|
||||
struct trie_node *new_node = calloc(1, sizeof(struct trie_node));
|
||||
|
||||
if (new_node == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
new_node->parent = parent;
|
||||
|
||||
new_node->num_children = 30;
|
||||
new_node->children = calloc(new_node->num_children,
|
||||
sizeof(struct trie_node *));
|
||||
if (new_node->children) {
|
||||
free(new_node);
|
||||
return NULL;
|
||||
}
|
||||
qb_list_init(&new_node->notifier_head);
|
||||
return new_node;
|
||||
}
|
||||
@ -206,6 +214,9 @@ trie_lookup(struct trie *t, const char *key, int32_t create_path)
|
||||
return NULL;
|
||||
}
|
||||
new_node = trie_new_node(t, cur_node);
|
||||
if (new_node == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
new_node->idx = idx;
|
||||
cur_node->children[idx] = new_node;
|
||||
}
|
||||
@ -308,6 +319,9 @@ trie_notify_add(qb_map_t * m, const char *key,
|
||||
}
|
||||
if (n) {
|
||||
f = malloc(sizeof(struct qb_map_notifier));
|
||||
if (f == NULL) {
|
||||
return -errno;
|
||||
}
|
||||
f->events = events;
|
||||
f->user_data = user_data;
|
||||
f->callback = fn;
|
||||
@ -357,6 +371,9 @@ trie_iter_create(struct qb_map *map, const char *prefix)
|
||||
{
|
||||
struct trie_iter *i = malloc(sizeof(struct trie_iter));
|
||||
struct trie *t = (struct trie *)map;
|
||||
if (i == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
i->i.m = map;
|
||||
i->prefix = prefix;
|
||||
i->n = t->header;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user