From 30613b224a9eed42d62a957adc2628d8b88870a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nils=20ANDR=C3=89-CHANG?= Date: Sat, 18 Jan 2020 16:53:43 +0000 Subject: [PATCH] Fix memory leak (#1187) Addresses https://github.com/CCExtractor/ccextractor/pull/402#discussion_r368041348 --- src/lib_ccx/ocr.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/lib_ccx/ocr.c b/src/lib_ccx/ocr.c index d4d5c9c7..1c0afccf 100644 --- a/src/lib_ccx/ocr.c +++ b/src/lib_ccx/ocr.c @@ -222,6 +222,14 @@ fail: } +/* + * The return value **has** to be freed: + * + * ```c + * BOX *box = ignore_alpha_at_edge(...); + * boxDestroy(&box); + * ``` + */ BOX* ignore_alpha_at_edge(png_byte *alpha, unsigned char* indata, int w, int h, PIX *in, PIX **out) { int i, j, index, start_y=0, end_y=0; @@ -248,7 +256,6 @@ BOX* ignore_alpha_at_edge(png_byte *alpha, unsigned char* indata, int w, int h, } cropWindow = boxCreate(start_y, 0, (w - (start_y + ( w - end_y) )), h - 1); *out = pixClipRectangle(in, cropWindow, NULL); - //boxDestroy(&cropWindow); return cropWindow; } @@ -325,7 +332,8 @@ char* ocr_bitmap(void* arg, png_color *palette,png_byte *alpha, unsigned char* i ppixel++; } } - ignore_alpha_at_edge(alpha, indata, w, h, pix, &cpix); + BOX *temp = ignore_alpha_at_edge(alpha, indata, w, h, pix, &cpix); + boxDestroy(&temp); // For the unquantized bitmap wpl = pixGetWpl(color_pix); @@ -682,7 +690,7 @@ char* ocr_bitmap(void* arg, png_color *palette,png_byte *alpha, unsigned char* i } // End Color Detection - // boxDestroy(crop_points); + boxDestroy(&crop_points); pixDestroy(&pix); pixDestroy(&cpix);