GUACAMOLE-958: Avoid race/deadlock in guacd_timed_client_free()
This commit is contained in:
parent
5ecad1c3d9
commit
783aa85c1b
@ -267,24 +267,24 @@ static int guacd_timed_client_free(guac_client* client, int timeout) {
|
|||||||
.tv_nsec = current_time.tv_usec * 1000
|
.tv_nsec = current_time.tv_usec * 1000
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Free the client in a separate thread, so we can time the free operation */
|
|
||||||
if (pthread_create(&client_free_thread, NULL,
|
|
||||||
guacd_client_free_thread, &free_operation))
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
/* The mutex associated with the pthread conditional and flag MUST be
|
/* The mutex associated with the pthread conditional and flag MUST be
|
||||||
* acquired before attempting to wait for the condition */
|
* acquired before attempting to wait for the condition */
|
||||||
if (pthread_mutex_lock(&free_operation.completed_mutex))
|
if (pthread_mutex_lock(&free_operation.completed_mutex))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
/* Wait a finite amount of time for the free operation to finish */
|
/* Free the client in a separate thread, so we can time the free operation */
|
||||||
if (pthread_cond_timedwait(&free_operation.completed_cond,
|
if (!pthread_create(&client_free_thread, NULL,
|
||||||
&free_operation.completed_mutex, &deadline))
|
guacd_client_free_thread, &free_operation)) {
|
||||||
return 1;
|
|
||||||
|
/* Wait a finite amount of time for the free operation to finish */
|
||||||
|
(void) pthread_cond_timedwait(&free_operation.completed_cond,
|
||||||
|
&free_operation.completed_mutex, &deadline);
|
||||||
|
}
|
||||||
|
|
||||||
|
(void) pthread_mutex_unlock(&free_operation.completed_mutex);
|
||||||
|
|
||||||
/* Return status of free operation */
|
/* Return status of free operation */
|
||||||
return !free_operation.completed;
|
return !free_operation.completed;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user