In ovs_db_init(), upon failure of either ovs_db_event_thread_init()
and/or ovs_db_poll_thread_init(), ovs_db_destroy() is invoked, in
order to release OVSDB data resources.
However, in the event that ovs_db_destroy() returns an error value,
some OVSDB resources are never released, and are consequently lost.
Resolve this issue by checking the return value of ovs_db_destroy()
and manually releasing the appropriate resources accordingly.
Fixes:
5a90d0e ("ovs_events: Address PR comments")
Signed-off-by: Kavanagh, Mark B <mark.b.kavanagh@intel.com>
ovs_db_t *ovs_db_init(const char *node, const char *service,
const char *unix_path, ovs_db_callback_t *cb) {
ovs_db_t *ovs_db_init(const char *node, const char *service,
const char *unix_path, ovs_db_callback_t *cb) {
/* sanity check */
if (node == NULL || service == NULL || unix_path == NULL)
return NULL;
/* sanity check */
if (node == NULL || service == NULL || unix_path == NULL)
return NULL;
/* init event thread */
if (ovs_db_event_thread_init(pdb) < 0) {
/* 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) {
}
/* 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;
+ }
+
+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,
}
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);
/* 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);
}
/* stop poll thread and destroy thread's private data */
}
/* stop poll thread and destroy thread's private data */