From a0ebc401d0b529ccede2f895566d4ab8f47986e5 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Thu, 18 May 2023 11:16:37 +0200 Subject: [PATCH] linux-dmabuf-v1: fix wlr_drm_format_set leak in feedback_compile() Fixes: 43b25fd34ebe ("dmabuf: Remove assumption that all mods are in fallback tranche") --- types/wlr_linux_dmabuf_v1.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/types/wlr_linux_dmabuf_v1.c b/types/wlr_linux_dmabuf_v1.c index 7e044c60..7145b980 100644 --- a/types/wlr_linux_dmabuf_v1.c +++ b/types/wlr_linux_dmabuf_v1.c @@ -509,7 +509,7 @@ static struct wlr_linux_dmabuf_feedback_v1_compiled *feedback_compile( const struct wlr_linux_dmabuf_feedback_v1_tranche *tranche = &tranches[i]; if (!wlr_drm_format_set_union(&all_formats, &all_formats, &tranche->formats)) { wlr_log(WLR_ERROR, "Failed to union scanout formats into one tranche"); - return false; + goto err_all_formats; } } @@ -534,7 +534,7 @@ static struct wlr_linux_dmabuf_feedback_v1_compiled *feedback_compile( wlr_log_errno(WLR_ERROR, "mmap failed"); close(rw_fd); close(ro_fd); - return NULL; + goto err_all_formats; } close(rw_fd); @@ -560,7 +560,7 @@ static struct wlr_linux_dmabuf_feedback_v1_compiled *feedback_compile( tranches_len * sizeof(struct wlr_linux_dmabuf_feedback_v1_compiled_tranche)); if (compiled == NULL) { close(ro_fd); - return NULL; + goto err_all_formats; } compiled->main_device = feedback->main_device; @@ -604,11 +604,15 @@ static struct wlr_linux_dmabuf_feedback_v1_compiled *feedback_compile( compiled_tranche->indices.size = n * sizeof(uint16_t); } + wlr_drm_format_set_finish(&all_formats); + return compiled; error_compiled: close(compiled->table_fd); free(compiled); +err_all_formats: + wlr_drm_format_set_finish(&all_formats); return NULL; }