From 67c9faab8fb6a125399d05a6cb1448daaea64c5a Mon Sep 17 00:00:00 2001 From: John McNamara Date: Fri, 25 Oct 2024 16:51:51 +0100 Subject: [PATCH] worksheet: fix resource leaks on error paths --- src/worksheet.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/worksheet.c b/src/worksheet.c index 971a95ba..c853f5f0 100644 --- a/src/worksheet.c +++ b/src/worksheet.c @@ -9626,12 +9626,16 @@ worksheet_set_selection(lxw_worksheet *self, /* Check that row and col are valid without storing. */ err = _check_dimensions(self, first_row, first_col, LXW_TRUE, LXW_TRUE); - if (err) + if (err) { + free(selection); return err; + } err = _check_dimensions(self, last_row, last_col, LXW_TRUE, LXW_TRUE); - if (err) + if (err) { + free(selection); return err; + } /* Set the cell range selection. Do this before swapping max/min to */ /* allow the selection direction to be reversed. */ @@ -10677,8 +10681,10 @@ worksheet_embed_image_opt(lxw_worksheet *self, /* Check and store the cell dimensions. */ err = _check_dimensions(self, row_num, col_num, LXW_FALSE, LXW_FALSE); - if (err) + if (err) { + fclose(image_stream); return err; + } /* Create a new object to hold the image properties. */ object_props = calloc(1, sizeof(lxw_object_properties));