From 50ecc5bbe4e24fdcae556c11e92de88778731203 Mon Sep 17 00:00:00 2001 From: gitlost Date: Wed, 12 Aug 2020 11:20:24 +0100 Subject: [PATCH] raster: #197 OUT_BUFFER_INTERMEDIATE fix memory leak (caught by clang-tidy) --- backend/raster.c | 11 +++++++---- backend/tests/test_raster.c | 16 +++++++++------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/backend/raster.c b/backend/raster.c index 98781d29..60177b9d 100644 --- a/backend/raster.c +++ b/backend/raster.c @@ -1104,12 +1104,15 @@ static int plot_raster_default(struct zint_symbol *symbol, int rotate_angle, int } error_number = save_raster_image_to_file(symbol, scale_height, scale_width, scaled_pixelbuf, rotate_angle, file_type); - free(scaled_pixelbuf); + if (rotate_angle || file_type != OUT_BUFFER || !(symbol->output_options & OUT_BUFFER_INTERMEDIATE)) { + free(scaled_pixelbuf); + } + free(pixelbuf); } else { error_number = save_raster_image_to_file(symbol, image_height, image_width, pixelbuf, rotate_angle, file_type); - } - if (rotate_angle || file_type != OUT_BUFFER || !(symbol->output_options & OUT_BUFFER_INTERMEDIATE)) { - free(pixelbuf); + if (rotate_angle || file_type != OUT_BUFFER || !(symbol->output_options & OUT_BUFFER_INTERMEDIATE)) { + free(pixelbuf); + } } return error_number; } diff --git a/backend/tests/test_raster.c b/backend/tests/test_raster.c index 5b7630de..048d3ae3 100644 --- a/backend/tests/test_raster.c +++ b/backend/tests/test_raster.c @@ -895,13 +895,15 @@ static void test_scale(int index, int debug) { /* 3*/ { BARCODE_PDF417, -1, -1, -1, 0.5, "1", 18, 6, 103, 206 * 0.5, 36 * 0.5, 0, 36 * 0.5, 170 * 0.5, 14 * 0.5 }, /* 4*/ { BARCODE_PDF417, -1, -1, -1, 1.0, "1", 18, 6, 103, 206 * 1.0, 36 * 1.0, 0, 36 * 1.0, 170 * 1.0, 14 * 1.0 }, /* 5*/ { BARCODE_PDF417, -1, -1, -1, 1.5, "1", 18, 6, 103, 206 * 1.5, 36 * 1.5, 0, 36 * 1.5, 170 * 1.5, 14 * 1.5 }, - /* 6*/ { BARCODE_PDF417, -1, -1, -1, 2.5, "1", 18, 6, 103, 206 * 2.5, 36 * 2.5, 0, 36 * 2.5, 170 * 2.5, 14 * 2.5 }, - /* 7*/ { BARCODE_PDF417, -1, -1, -1, 3.0, "1", 18, 6, 103, 206 * 3.0, 36 * 3.0, 0, 36 * 3.0, 170 * 3.0, 14 * 3.0 }, - /* 8*/ { BARCODE_PDF417, -1, 3, BARCODE_BOX, 0, "1", 18, 6, 103, 218, 48, 0, 48, 176, 14 }, // With no scaling - /* 9*/ { BARCODE_PDF417, -1, 3, BARCODE_BOX, 0.6, "1", 18, 6, 103, 218 * 0.6, 48 * 0.6, 0, 48 * 0.6, 176 * 0.6 + 1, 14 * 0.6 }, // +1 set_col due to some scaling inversion difference - /* 10*/ { BARCODE_PDF417, -1, 3, BARCODE_BOX, 1.6, "1", 18, 6, 103, 218 * 1.6, 48 * 1.6, 0, 48 * 1.6, 176 * 1.6 + 1, 14 * 1.6 }, // +1 set_col due to some scaling inversion difference - /* 11*/ { BARCODE_PDF417, -1, 3, BARCODE_BOX, 1.5, "1", 18, 6, 103, 218 * 1.5, 48 * 1.5, 0, 48 * 1.5, 176 * 1.5, 14 * 1.5 }, - /* 12*/ { BARCODE_PDF417, -1, 3, BARCODE_BOX, 2.5, "1", 18, 6, 103, 218 * 2.5, 48 * 2.5, 0, 48 * 2.5, 176 * 2.5, 14 * 2.5 }, + /* 6*/ { BARCODE_PDF417, -1, -1, -1, 2.0, "1", 18, 6, 103, 206 * 2.0, 36 * 2.0, 0, 36 * 2.0, 170 * 2.0, 14 * 2.0 }, + /* 7*/ { BARCODE_PDF417, -1, -1, -1, 2.5, "1", 18, 6, 103, 206 * 2.5, 36 * 2.5, 0, 36 * 2.5, 170 * 2.5, 14 * 2.5 }, + /* 8*/ { BARCODE_PDF417, -1, -1, -1, 3.0, "1", 18, 6, 103, 206 * 3.0, 36 * 3.0, 0, 36 * 3.0, 170 * 3.0, 14 * 3.0 }, + /* 9*/ { BARCODE_PDF417, -1, 3, BARCODE_BOX, 0, "1", 18, 6, 103, 218, 48, 0, 48, 176, 14 }, // With no scaling + /* 10*/ { BARCODE_PDF417, -1, 3, BARCODE_BOX, 0.6, "1", 18, 6, 103, 218 * 0.6, 48 * 0.6, 0, 48 * 0.6, 176 * 0.6 + 1, 14 * 0.6 }, // +1 set_col due to some scaling inversion difference + /* 11*/ { BARCODE_PDF417, -1, 3, BARCODE_BOX, 1.6, "1", 18, 6, 103, 218 * 1.6, 48 * 1.6, 0, 48 * 1.6, 176 * 1.6 + 1, 14 * 1.6 }, // +1 set_col due to some scaling inversion difference + /* 12*/ { BARCODE_PDF417, -1, 3, BARCODE_BOX, 1.5, "1", 18, 6, 103, 218 * 1.5, 48 * 1.5, 0, 48 * 1.5, 176 * 1.5, 14 * 1.5 }, + /* 13*/ { BARCODE_PDF417, -1, 3, BARCODE_BOX, 2.5, "1", 18, 6, 103, 218 * 2.5, 48 * 2.5, 0, 48 * 2.5, 176 * 2.5, 14 * 2.5 }, + /* 14*/ { BARCODE_PDF417, -1, 3, OUT_BUFFER_INTERMEDIATE, 1.3, "1", 18, 6, 103, 206 * 1.3, 36 * 1.3, 0, 36 * 1.3, 170 * 1.3 + 1, 14 * 1.3 }, // +1 set_col due to some scaling inversion difference }; int data_size = ARRAY_SIZE(data);