Fix memory leak (#1187)

Addresses https://github.com/CCExtractor/ccextractor/pull/402#discussion_r368041348
This commit is contained in:
Nils ANDRÉ-CHANG 2020-01-18 16:53:43 +00:00 committed by Carlos Fernandez Sanz
parent 19241744d7
commit 30613b224a

View File

@ -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);