From 3fb76843363bf619d41f97d873d8919743d0b868 Mon Sep 17 00:00:00 2001 From: Simon Lees Date: Mon, 18 Nov 2024 12:17:09 +1030 Subject: [PATCH] lua-imlib2: fix memory leak If you frequently use this function to draw new images this leak becomes quite significant --- lua/libcairo_imlib2_helper.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lua/libcairo_imlib2_helper.h b/lua/libcairo_imlib2_helper.h index 902a45da0..14006d13c 100644 --- a/lua/libcairo_imlib2_helper.h +++ b/lua/libcairo_imlib2_helper.h @@ -5,7 +5,7 @@ * Please see COPYING for details * * Copyright (c) 2005-2024 Brenden Matthews, Philip Kovacs, et. al. - * (see AUTHORS) + * (see AUTHORS) * All rights reserved. * * This program is free software: you can redistribute it and/or modify @@ -61,7 +61,6 @@ void cairo_place_image(const char *file, cairo_t *cr, int x, int y, return; } - /* create scaled version of image to later extract the alpha channel */ alpha_image = imlib_create_cropped_scaled_image(0, 0, w, h, width, height); /* create temporary image */ @@ -151,6 +150,8 @@ void cairo_draw_image(const char *file, cairo_surface_t *cs, int x, int y, cr = cairo_create(cs); cairo_place_image(file, cr, x, y, scaled_w, scaled_h, 1.0); + imlib_context_set_image(image); + imlib_free_image_and_decache(); cairo_destroy(cr); }