ceph plugin: Fix #2572
[collectd.git] / src / utils_ovs.c
index e9e841e..3c448e3 100644 (file)
@@ -263,12 +263,11 @@ static void ovs_db_callback_remove(ovs_db_t *pdb, ovs_callback_t *del_cb) {
 /* Remove all callbacks form OVS DB object */
 static void ovs_db_callback_remove_all(ovs_db_t *pdb) {
   pthread_mutex_lock(&pdb->mutex);
-  for (ovs_callback_t *del_cb = pdb->remote_cb; pdb->remote_cb;
-       del_cb = pdb->remote_cb) {
+  while (pdb->remote_cb != NULL) {
+    ovs_callback_t *del_cb = pdb->remote_cb;
     pdb->remote_cb = del_cb->next;
-    free(del_cb);
+    sfree(del_cb);
   }
-  pdb->remote_cb = NULL;
   pthread_mutex_unlock(&pdb->mutex);
 }
 
@@ -935,6 +934,7 @@ static int ovs_db_event_thread_init(ovs_db_t *pdb) {
 }
 
 /* Destroy EVENT thread */
+/* XXX: Must hold pdb->mutex when calling! */
 static int ovs_db_event_thread_destroy(ovs_db_t *pdb) {
   if (pthread_equal(pdb->event_thread.tid, (pthread_t){0})) {
     /* already destroyed */
@@ -974,6 +974,7 @@ static int ovs_db_poll_thread_init(ovs_db_t *pdb) {
 }
 
 /* Destroy POLL thread */
+/* XXX: Must hold pdb->mutex when calling! */
 static int ovs_db_poll_thread_destroy(ovs_db_t *pdb) {
   if (pthread_equal(pdb->poll_thread.tid, (pthread_t){0})) {
     /* already destroyed */
@@ -1002,9 +1003,10 @@ ovs_db_t *ovs_db_init(const char *node, const char *service,
     return NULL;
 
   /* allocate db data & fill it */
-  ovs_db_t *pdb = pdb = calloc(1, sizeof(*pdb));
+  ovs_db_t *pdb = calloc(1, sizeof(*pdb));
   if (pdb == NULL)
     return NULL;
+  pdb->sock = -1;
 
   /* store the OVS DB address */
   sstrncpy(pdb->node, node, sizeof(pdb->node));
@@ -1046,7 +1048,6 @@ ovs_db_t *ovs_db_init(const char *node, const char *service,
   }
 
   /* init polling thread */
-  pdb->sock = -1;
   if (ovs_db_poll_thread_init(pdb) < 0) {
     ovs_db_destroy(pdb);
     return NULL;
@@ -1261,13 +1262,13 @@ int ovs_db_destroy(ovs_db_t *pdb) {
   /* stop poll thread */
   if (ovs_db_event_thread_destroy(pdb) < 0) {
     OVS_ERROR("destroy poll thread failed");
-    ovs_db_ret = (-1);
+    ovs_db_ret = -1;
   }
 
   /* stop event thread */
   if (ovs_db_poll_thread_destroy(pdb) < 0) {
     OVS_ERROR("stop event thread failed");
-    ovs_db_ret = (-1);
+    ovs_db_ret = -1;
   }
 
   pthread_mutex_unlock(&pdb->mutex);