X-Git-Url: https://git.octo.it/?p=collectd.git;a=blobdiff_plain;f=src%2Futils_ovs.c;h=3b7236cadc4642a2c4d4e0f128eed4e234f7bb0f;hp=f98841cdaee2b162b55eae6726d1bc398d269470;hb=ec51ddee94fa2ba1e01fe0e336ccc9c190a198ff;hpb=7858bf59eeed7b8769dd7258af7ea223e37287e4 diff --git a/src/utils_ovs.c b/src/utils_ovs.c index f98841cd..3b7236ca 100644 --- a/src/utils_ovs.c +++ b/src/utils_ovs.c @@ -191,7 +191,7 @@ struct ovs_db_s { }; /* Global variables */ -static uint64_t ovs_uid = 0; +static uint64_t ovs_uid; static pthread_mutex_t ovs_uid_mutex = PTHREAD_MUTEX_INITIALIZER; /* Post an event to event thread. @@ -209,7 +209,7 @@ static void ovs_db_event_post(ovs_db_t *pdb, int event) { /* Check if POLL thread is still running. Returns * 1 if running otherwise 0 is returned */ -static _Bool ovs_db_poll_is_running(ovs_db_t *pdb) { +static bool ovs_db_poll_is_running(ovs_db_t *pdb) { int state = 0; pthread_mutex_lock(&pdb->poll_thread.mutex); state = pdb->poll_thread.state; @@ -1001,6 +1001,8 @@ static int ovs_db_poll_thread_destroy(ovs_db_t *pdb) { ovs_db_t *ovs_db_init(const char *node, const char *service, const char *unix_path, ovs_db_callback_t *cb) { + int ret; + /* sanity check */ if (node == NULL || service == NULL || unix_path == NULL) return NULL; @@ -1046,16 +1048,25 @@ ovs_db_t *ovs_db_init(const char *node, const char *service, /* init event thread */ if (ovs_db_event_thread_init(pdb) < 0) { - ovs_db_destroy(pdb); - return NULL; + ret = ovs_db_destroy(pdb); + if (ret > 0) + goto failure; } /* init polling thread */ if (ovs_db_poll_thread_init(pdb) < 0) { - ovs_db_destroy(pdb); - return NULL; + ret = ovs_db_destroy(pdb); + if (ret > 0) { + ovs_db_event_thread_data_destroy(pdb); + goto failure; + } } return pdb; + +failure: + pthread_mutex_destroy(&pdb->mutex); + sfree(pdb); + return NULL; } int ovs_db_send_request(ovs_db_t *pdb, const char *method, const char *params, @@ -1265,7 +1276,7 @@ int ovs_db_destroy(ovs_db_t *pdb) { /* try to lock the structure before releasing */ if ((ret = pthread_mutex_lock(&pdb->mutex))) { OVS_ERROR("pthread_mutex_lock() DB mutex lock failed (%d)", ret); - return -1; + return ret; } /* stop poll thread and destroy thread's private data */