mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-05 18:18:06 +02:00
util/queue: Don't crash in util_queue_destroy when init failed
This simplifies the error exit paths for drivers that use these queues. v2: Move allocation of queue->jobs after initializing the mutxes and condition variables. Noticed by Ken. Reviewed-by: Kenneth Graunke <kenneth@whitecape.org> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11229>
This commit is contained in:
parent
d2b4a59474
commit
d78e980523
1 changed files with 9 additions and 6 deletions
|
|
@ -445,11 +445,6 @@ util_queue_init(struct util_queue *queue,
|
|||
queue->max_jobs = max_jobs;
|
||||
queue->global_data = global_data;
|
||||
|
||||
queue->jobs = (struct util_queue_job*)
|
||||
calloc(max_jobs, sizeof(struct util_queue_job));
|
||||
if (!queue->jobs)
|
||||
goto fail;
|
||||
|
||||
(void) mtx_init(&queue->lock, mtx_plain);
|
||||
(void) mtx_init(&queue->finish_lock, mtx_plain);
|
||||
|
||||
|
|
@ -457,6 +452,11 @@ util_queue_init(struct util_queue *queue,
|
|||
cnd_init(&queue->has_queued_cond);
|
||||
cnd_init(&queue->has_space_cond);
|
||||
|
||||
queue->jobs = (struct util_queue_job*)
|
||||
calloc(max_jobs, sizeof(struct util_queue_job));
|
||||
if (!queue->jobs)
|
||||
goto fail;
|
||||
|
||||
queue->threads = (thrd_t*) calloc(queue->max_threads, sizeof(thrd_t));
|
||||
if (!queue->threads)
|
||||
goto fail;
|
||||
|
|
@ -534,7 +534,10 @@ void
|
|||
util_queue_destroy(struct util_queue *queue)
|
||||
{
|
||||
util_queue_kill_threads(queue, 0, false);
|
||||
remove_from_atexit_list(queue);
|
||||
|
||||
/* This makes it safe to call on a queue that failedutil_queue_init. */
|
||||
if (queue->head.next != NULL)
|
||||
remove_from_atexit_list(queue);
|
||||
|
||||
cnd_destroy(&queue->has_space_cond);
|
||||
cnd_destroy(&queue->has_queued_cond);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue