Skip to content

Commit

Permalink
Merge pull request #713 from me22bee/_gdImageGd2
Browse files Browse the repository at this point in the history
gdImageGd2Ptr memory leak
  • Loading branch information
pierrejoye committed Aug 24, 2021
2 parents b61fc2d + a1d4caa commit c5fd25c
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/gd_gd2.c
Expand Up @@ -910,9 +910,11 @@ _gd2PutHeader (gdImagePtr im, gdIOCtx * out, int cs, int fmt, int cx, int cy)

}

static void
/* returns 0 on success, 1 on failure */
static int
_gdImageGd2 (gdImagePtr im, gdIOCtx * out, int cs, int fmt)
{
int ret = 0;
int ncx, ncy, cx, cy;
int x, y, ylo, yhi, xlo, xhi;
int chunkLen;
Expand Down Expand Up @@ -974,10 +976,12 @@ _gdImageGd2 (gdImagePtr im, gdIOCtx * out, int cs, int fmt)
/* */
chunkData = gdCalloc (cs * bytesPerPixel * cs, 1);
if (!chunkData) {
ret = 1;
goto fail;
}
compData = gdCalloc (compMax, 1);
if (!compData) {
ret = 1;
goto fail;
}

Expand All @@ -992,6 +996,7 @@ _gdImageGd2 (gdImagePtr im, gdIOCtx * out, int cs, int fmt)

chunkIdx = gdCalloc (idxSize * sizeof (t_chunk_info), 1);
if (!chunkIdx) {
ret = 1;
goto fail;
}
};
Expand Down Expand Up @@ -1107,6 +1112,8 @@ _gdImageGd2 (gdImagePtr im, gdIOCtx * out, int cs, int fmt)
}
GD2_DBG (printf ("Done\n"));

return ret;

}

/*
Expand All @@ -1128,8 +1135,13 @@ BGD_DECLARE(void *) gdImageGd2Ptr (gdImagePtr im, int cs, int fmt, int *size)
void *rv;
gdIOCtx *out = gdNewDynamicCtx (2048, NULL);
if (out == NULL) return NULL;
_gdImageGd2 (im, out, cs, fmt);
rv = gdDPExtractData (out, size);

if (_gdImageGd2(im, out, cs, fmt)) {
rv = NULL;
} else {
rv = gdDPExtractData(out, size);
}

out->gd_free (out);
return rv;
}
Expand Down

0 comments on commit c5fd25c

Please sign in to comment.