mirror of
https://github.com/kichikuou/xsystem35-sdl2.git
synced 2026-09-22 22:48:08 +03:00
Fix memory leak in qnt_extract
This commit is contained in:
@@ -46,26 +46,14 @@
|
||||
*/
|
||||
#define ZLIBBUF_MARGIN 5*1024
|
||||
|
||||
/*
|
||||
static methods
|
||||
*/
|
||||
static qnt_header *extract_header(BYTE *b);
|
||||
static void extract_pixel(qnt_header *qnt, BYTE *pic, BYTE *b);
|
||||
static void extract_alpha(qnt_header *qnt, BYTE *pic, BYTE *b);
|
||||
|
||||
|
||||
/*
|
||||
Get information from header
|
||||
|
||||
b: raw data
|
||||
|
||||
return: acquired qnt information object
|
||||
qnt: acquired qnt information object
|
||||
*/
|
||||
static qnt_header *extract_header(BYTE *b) {
|
||||
qnt_header *qnt = malloc(sizeof(qnt_header));
|
||||
int rsv0;
|
||||
|
||||
rsv0 = LittleEndian_getDW(b, 4);
|
||||
static void extract_header(BYTE *b, qnt_header *qnt) {
|
||||
int rsv0 = LittleEndian_getDW(b, 4);
|
||||
if (rsv0 == 0) {
|
||||
qnt->hdr_size = 48;
|
||||
qnt->x0 = LittleEndian_getDW(b, 8);
|
||||
@@ -87,8 +75,6 @@ static qnt_header *extract_header(BYTE *b) {
|
||||
qnt->pixel_size = LittleEndian_getDW(b, 36);
|
||||
qnt->alpha_size = LittleEndian_getDW(b, 40);
|
||||
}
|
||||
|
||||
return qnt;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -242,21 +228,22 @@ boolean qnt_checkfmt(BYTE *data) {
|
||||
*/
|
||||
cgdata *qnt_extract(BYTE *data) {
|
||||
cgdata *cg = calloc(1, sizeof(cgdata));
|
||||
qnt_header *qnt = extract_header(data);
|
||||
qnt_header qnt;
|
||||
extract_header(data, &qnt);
|
||||
|
||||
cg->pic = malloc(sizeof(BYTE) * ((qnt->width+10) * (qnt->height+10) * 3));
|
||||
extract_pixel(qnt, cg->pic, data + qnt->hdr_size);
|
||||
cg->pic = malloc(sizeof(BYTE) * ((qnt.width+10) * (qnt.height+10) * 3));
|
||||
extract_pixel(&qnt, cg->pic, data + qnt.hdr_size);
|
||||
|
||||
if (qnt->alpha_size != 0) {
|
||||
cg->alpha = malloc(sizeof(BYTE) * ((qnt->width+10) * (qnt->height+10)));
|
||||
extract_alpha(qnt, (BYTE *)cg->alpha, data + qnt->hdr_size + qnt->pixel_size);
|
||||
if (qnt.alpha_size != 0) {
|
||||
cg->alpha = malloc(sizeof(BYTE) * ((qnt.width+10) * (qnt.height+10)));
|
||||
extract_alpha(&qnt, (BYTE *)cg->alpha, data + qnt.hdr_size + qnt.pixel_size);
|
||||
}
|
||||
|
||||
cg->type = ALCG_QNT;
|
||||
cg->x = qnt->x0;
|
||||
cg->y = qnt->y0;
|
||||
cg->width = qnt->width;
|
||||
cg->height = qnt->height;
|
||||
cg->x = qnt.x0;
|
||||
cg->y = qnt.y0;
|
||||
cg->width = qnt.width;
|
||||
cg->height = qnt.height;
|
||||
cg->pal = NULL;
|
||||
|
||||
return cg;
|
||||
|
||||
Reference in New Issue
Block a user