From ac8415c24ffea645105c3859e814843e81c97f8a Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Mon, 16 Jan 2017 16:27:22 -0800 Subject: Start of event framework. This compiles correctly, but doesn't actually deliver events yet. As part of this, I've made most of the initializables in nng safe to tear-down if uninitialized (or set to zero e.g. via calloc). This makes it loads easier to write the teardown on error code, since I can deinit everything, without worrying about which things have been initialized and which have not. --- src/protocol/pubsub/pub.c | 10 +++++++--- src/protocol/pubsub/sub.c | 16 ++++++++++------ 2 files changed, 17 insertions(+), 9 deletions(-) (limited to 'src/protocol/pubsub') diff --git a/src/protocol/pubsub/pub.c b/src/protocol/pubsub/pub.c index a167d523..5617d92c 100644 --- a/src/protocol/pubsub/pub.c +++ b/src/protocol/pubsub/pub.c @@ -62,7 +62,9 @@ nni_pub_sock_fini(void *arg) { nni_pub_sock *pub = arg; - NNI_FREE_STRUCT(pub); + if (pub != NULL) { + NNI_FREE_STRUCT(pub); + } } @@ -93,8 +95,10 @@ nni_pub_pipe_fini(void *arg) { nni_pub_pipe *pp = arg; - nni_msgq_fini(pp->sendq); - NNI_FREE_STRUCT(pp); + if (pp != NULL) { + nni_msgq_fini(pp->sendq); + NNI_FREE_STRUCT(pp); + } } diff --git a/src/protocol/pubsub/sub.c b/src/protocol/pubsub/sub.c index 9390b0d2..cd8dd87c 100644 --- a/src/protocol/pubsub/sub.c +++ b/src/protocol/pubsub/sub.c @@ -65,12 +65,14 @@ nni_sub_sock_fini(void *arg) nni_sub_sock *sub = arg; nni_sub_topic *topic; - while ((topic = nni_list_first(&sub->topics)) != NULL) { - nni_list_remove(&sub->topics, topic); - nni_free(topic->buf, topic->len); - NNI_FREE_STRUCT(topic); + if (sub != NULL) { + while ((topic = nni_list_first(&sub->topics)) != NULL) { + nni_list_remove(&sub->topics, topic); + nni_free(topic->buf, topic->len); + NNI_FREE_STRUCT(topic); + } + NNI_FREE_STRUCT(sub); } - NNI_FREE_STRUCT(sub); } @@ -94,7 +96,9 @@ nni_sub_pipe_fini(void *arg) { nni_sub_pipe *sp = arg; - NNI_FREE_STRUCT(sp); + if (sp != NULL) { + NNI_FREE_STRUCT(sp); + } } -- cgit v1.2.3-70-g09d2