summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcus Fritzsch <marcus_fritzsch@mentor.com>2017-09-05 09:48:46 +0200
committerMarcus Fritzsch <marcus_fritzsch@mentor.com>2017-09-14 14:04:51 +0200
commitd53c8301bf1d51d4001a93acdb54adf40c78e207 (patch)
tree3a1ad5b21d784d122dc3e255f927850fbef8e0de
parentdaac597f2ffe16f19b0669e69c91a323b0122d4b (diff)
AFBClient: prevent init if already initialized
Signed-off-by: Marcus Fritzsch <marcus_fritzsch@mentor.com>
-rw-r--r--AFBClient.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/AFBClient.cpp b/AFBClient.cpp
index 5ffad29..497b746 100644
--- a/AFBClient.cpp
+++ b/AFBClient.cpp
@@ -206,7 +206,6 @@ AFBClient::Impl::~Impl() {
TRACE();
afb_wsj1_unref(wsj1);
sd_event_unref(loop);
- loop = nullptr;
}
int AFBClient::Impl::init(int port, char const *token) {
@@ -214,6 +213,12 @@ int AFBClient::Impl::init(int port, char const *token) {
char *uribuf = nullptr;
int rc = -1;
+ if (this->loop != nullptr && this->wsj1 != nullptr) {
+ fputs("AFBClient instance is already initialized!\n", stderr);
+ rc = -EALREADY;
+ goto fail;
+ }
+
if ((token == nullptr) || strlen(token) > token_maxlen) {
fprintf(stderr, "Token is invalid\n");
rc = -EINVAL;
@@ -248,7 +253,8 @@ int AFBClient::Impl::init(int port, char const *token) {
wsj1 = afb_ws_client_connect_wsj1(
loop, uribuf, const_cast<struct afb_wsj1_itf *>(&itf), this);
if (wsj1 == nullptr) {
- sd_event_unref(loop);
+ sd_event_unref(this->loop);
+ this->loop = nullptr;
fprintf(stderr, "Connection to %s failed: %m\n", uribuf);
rc = -errno;
goto fail;