Skip to content

Commit

Permalink
vhost: check return of mutex initialization
Browse files Browse the repository at this point in the history
Check return value of pthread_mutex_init(). Also destroy
mutex in case of other erros before returning.

Signed-off-by: Jens Freimann <jfreimann@redhat.com>
Acked-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
  • Loading branch information
jensfr authored and yuanhanliu committed Jul 4, 2017
1 parent d6983a7 commit 2dfeebe
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/librte_vhost/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -445,13 +445,22 @@ vhost_user_reconnect_init(void)
{
int ret;

pthread_mutex_init(&reconn_list.mutex, NULL);
ret = pthread_mutex_init(&reconn_list.mutex, NULL);
if (ret < 0) {
RTE_LOG(ERR, VHOST_CONFIG, "failed to initialize mutex");
return ret;
}
TAILQ_INIT(&reconn_list.head);

ret = pthread_create(&reconn_tid, NULL,
vhost_user_client_reconnect, NULL);
if (ret < 0)
if (ret < 0) {
RTE_LOG(ERR, VHOST_CONFIG, "failed to create reconnect thread");
if (pthread_mutex_destroy(&reconn_list.mutex)) {
RTE_LOG(ERR, VHOST_CONFIG,
"failed to destroy reconnect mutex");
}
}

return ret;
}
Expand Down

0 comments on commit 2dfeebe

Please sign in to comment.