hwcontext_vulkan: free temporary array once unneeded

Fixes a small memory leak.
This also prevents leaks on malloc/mutex init errors.
This commit is contained in:
Lynne 2023-06-13 04:36:54 +02:00
parent b4d5baa8b0
commit d0f1d937fe
No known key found for this signature in database
GPG Key ID: A2FEA5F03F034464
1 changed files with 9 additions and 2 deletions

View File

@ -1427,24 +1427,31 @@ static int vulkan_device_init(AVHWDeviceContext *ctx)
vk->GetPhysicalDeviceQueueFamilyProperties(hwctx->phys_dev, &qf_num, qf);
p->qf_mutex = av_calloc(qf_num, sizeof(*p->qf_mutex));
if (!p->qf_mutex)
if (!p->qf_mutex) {
av_free(qf);
return AVERROR(ENOMEM);
}
p->nb_tot_qfs = qf_num;
for (uint32_t i = 0; i < qf_num; i++) {
p->qf_mutex[i] = av_calloc(qf[i].queueCount, sizeof(**p->qf_mutex));
if (!p->qf_mutex[i])
if (!p->qf_mutex[i]) {
av_free(qf);
return AVERROR(ENOMEM);
}
for (uint32_t j = 0; j < qf[i].queueCount; j++) {
err = pthread_mutex_init(&p->qf_mutex[i][j], NULL);
if (err != 0) {
av_log(ctx, AV_LOG_ERROR, "pthread_mutex_init failed : %s\n",
av_err2str(err));
av_free(qf);
return AVERROR(err);
}
}
}
av_free(qf);
graph_index = hwctx->queue_family_index;
comp_index = hwctx->queue_family_comp_index;
tx_index = hwctx->queue_family_tx_index;