Skip to content

Commit

Permalink
Make sure memory is freed on error conditions.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelrsweet committed Oct 9, 2024
1 parent 74dfefd commit 8f2c47c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
3 changes: 0 additions & 3 deletions pdfio-stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -1064,9 +1064,6 @@ stream_read(pdfio_stream_t *st, // I - Stream
st->flate.next_out = (Bytef *)buffer;
st->flate.avail_out = (uInt)bytes;

avail_in = st->flate.avail_in;
avail_out = st->flate.avail_out;

if ((status = inflate(&(st->flate), Z_NO_FLUSH)) < Z_OK)
{
_pdfioFileError(st->pdf, "Unable to decompress stream data for object %ld: %s", (long)st->obj->number, zstrerror(status));
Expand Down
8 changes: 8 additions & 0 deletions ttf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1309,6 +1309,8 @@ read_cmap(ttf_t *font) // I - Font
if (segment->startCode > segment->endCode)
{
errorf(font, "Bad cmap table segment %u to %u.", segments->startCode, segment->endCode);
free(segments);
free(glyphIdArray);
return (false);
}

Expand All @@ -1326,6 +1328,8 @@ read_cmap(ttf_t *font) // I - Font
if (font->num_cmap == 0 || font->num_cmap > TTF_FONT_MAX_CHAR)
{
errorf(font, "Invalid cmap table with %u characters.", (unsigned)font->num_cmap);
free(segments);
free(glyphIdArray);
return (false);
}

Expand Down Expand Up @@ -1422,6 +1426,7 @@ read_cmap(ttf_t *font) // I - Font
if (group->startCharCode > group->endCharCode)
{
errorf(font, "Bad cmap table segment %u to %u.", group->startCharCode, group->endCharCode);
free(groups);
return (false);
}

Expand All @@ -1436,6 +1441,7 @@ read_cmap(ttf_t *font) // I - Font
if (font->num_cmap == 0 || font->num_cmap > TTF_FONT_MAX_CHAR)
{
errorf(font, "Invalid cmap table with %u characters.", (unsigned)font->num_cmap);
free(groups);
return (false);
}

Expand Down Expand Up @@ -1511,6 +1517,7 @@ read_cmap(ttf_t *font) // I - Font
if (group->startCharCode > group->endCharCode)
{
errorf(font, "Bad cmap table segment %u to %u.", group->startCharCode, group->endCharCode);
free(groups);
return (false);
}

Expand All @@ -1525,6 +1532,7 @@ read_cmap(ttf_t *font) // I - Font
if (font->num_cmap == 0 || font->num_cmap > TTF_FONT_MAX_CHAR)
{
errorf(font, "Invalid cmap table with %u characters.", (unsigned)font->num_cmap);
free(groups);
return (false);
}

Expand Down

0 comments on commit 8f2c47c

Please sign in to comment.