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;
/* 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,
/* 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 */
/* check first element of the array */
str_val = YAJL_GET_STRING(array_values[0]);
- if (strcmp("map", str_val) != 0)
+ if (str_val == NULL || strcmp("map", str_val) != 0)
return NULL;
/* try to find map value by map key */
+ if (YAJL_GET_ARRAY(array_values[1]) == NULL)
+ return NULL;
+
map_len = YAJL_GET_ARRAY(array_values[1])->len;
map_values = YAJL_GET_ARRAY(array_values[1])->values;
for (size_t i = 0; i < map_len; i++) {
/* check YAJL array */
- if (!YAJL_IS_ARRAY(map_values[i]))
+ if (!YAJL_IS_ARRAY(map_values[i]) || YAJL_GET_ARRAY(map_values[i]) == NULL)
break;
/* check a database pair value (2-element, first one represents a key
/* return map value if given key equals map key */
str_val = YAJL_GET_STRING(array_values[0]);
- if (strcmp(key, str_val) == 0)
+ if (str_val != NULL && strcmp(key, str_val) == 0)
return array_values[1];
}
return NULL;