From f8bc6c866373934fea3093124b708d857adecbf2 Mon Sep 17 00:00:00 2001 From: "Eric R. Smith" Date: Wed, 11 Dec 2024 11:34:51 -0400 Subject: [PATCH] panfrost: fix potential memory leak MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In the very unlikely case that the packed AFBC image will not save (enough) memory, we abort packing. In this case we should free the BO associated with the metadata. Fixes: 5a928f7563a ("panfrost: Add env variable for max AFBC packing ratio") Reviewed-by: Louis-Francis Ratté-Boulianne Reviewed-by: Erik Faye-Lund Part-of: --- src/gallium/drivers/panfrost/pan_resource.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/gallium/drivers/panfrost/pan_resource.c b/src/gallium/drivers/panfrost/pan_resource.c index a45682878eb..eacdb5419bc 100644 --- a/src/gallium/drivers/panfrost/pan_resource.c +++ b/src/gallium/drivers/panfrost/pan_resource.c @@ -1674,9 +1674,10 @@ panfrost_pack_afbc(struct panfrost_context *ctx, unsigned old_size = panfrost_bo_size(prsrc->bo); unsigned ratio = 100 * new_size / old_size; - if (ratio > screen->max_afbc_packing_ratio) + if (ratio > screen->max_afbc_packing_ratio) { + panfrost_bo_unreference(metadata_bo); return; - + } perf_debug(ctx, "%i%%: %i KB -> %i KB\n", ratio, old_size / 1024, new_size / 1024);