diff options
author | maryam ebrahimzadeh <maryam.ebr@student.sharif.edu> | 2021-07-19 18:52:50 +0430 |
---|---|---|
committer | maryam ebrahimzadeh <maryam.ebr@student.sharif.edu> | 2021-07-19 18:52:50 +0430 |
commit | e95059590fadaabd9aadc0c0489804d75a3c5d52 (patch) | |
tree | babd1c4c24ee97d34898c30075ed044d6cc4664a /src | |
parent | bfc90ac2a6c4119ae6f9e57cc7d7e5d314500f2e (diff) | |
download | libgd-e95059590fadaabd9aadc0c0489804d75a3c5d52.tar.gz |
gdImageGd2Ptr memory leak
Diffstat (limited to 'src')
-rw-r--r-- | src/gd_gd2.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/gd_gd2.c b/src/gd_gd2.c index 760e85b..84ec533 100644 --- a/src/gd_gd2.c +++ b/src/gd_gd2.c @@ -1,4 +1,4 @@ -/* +
/* * gd_gd2.c * * Implements the I/O and support for the GD2 format. @@ -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; @@ -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; } @@ -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; } }; @@ -1107,6 +1112,8 @@ fail: } GD2_DBG (printf ("Done\n")); + return ret; + } /* @@ -1128,8 +1135,11 @@ 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; } |