Skip to content

Commit

Permalink
Convert uses of _TIFFmalloc/realloc/calloc/free to the Ext functions
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Nov 23, 2022
1 parent b88c3f9 commit 553bb4b
Show file tree
Hide file tree
Showing 27 changed files with 460 additions and 439 deletions.
24 changes: 12 additions & 12 deletions libtiff/tif_aux.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ _TIFFCheckRealloc(TIFF* tif, void* buffer,
*/
if (count != 0)
{
cp = _TIFFrealloc(buffer, count);
cp = _TIFFreallocExt(tif, buffer, count);
}

if (cp == NULL) {
Expand All @@ -123,7 +123,7 @@ _TIFFCheckMalloc(TIFF* tif, tmsize_t nmemb, tmsize_t elem_size, const char* what
}

static int
TIFFDefaultTransferFunction(TIFFDirectory* td)
TIFFDefaultTransferFunction(TIFF* tif, TIFFDirectory* td)
{
uint16_t **tf = td->td_transferfunction;
tmsize_t i, n, nbytes;
Expand All @@ -134,7 +134,7 @@ TIFFDefaultTransferFunction(TIFFDirectory* td)

n = ((tmsize_t)1)<<td->td_bitspersample;
nbytes = n * sizeof (uint16_t);
tf[0] = (uint16_t *)_TIFFmalloc(nbytes);
tf[0] = (uint16_t *)_TIFFmallocExt(tif, nbytes);
if (tf[0] == NULL)
return 0;
tf[0][0] = 0;
Expand All @@ -144,11 +144,11 @@ TIFFDefaultTransferFunction(TIFFDirectory* td)
}

if (td->td_samplesperpixel - td->td_extrasamples > 1) {
tf[1] = (uint16_t *)_TIFFmalloc(nbytes);
tf[1] = (uint16_t *)_TIFFmallocExt(tif, nbytes);
if(tf[1] == NULL)
goto bad;
_TIFFmemcpy(tf[1], tf[0], nbytes);
tf[2] = (uint16_t *)_TIFFmalloc(nbytes);
tf[2] = (uint16_t *)_TIFFmallocExt(tif, nbytes);
if (tf[2] == NULL)
goto bad;
_TIFFmemcpy(tf[2], tf[0], nbytes);
Expand All @@ -157,21 +157,21 @@ TIFFDefaultTransferFunction(TIFFDirectory* td)

bad:
if (tf[0])
_TIFFfree(tf[0]);
_TIFFfreeExt(tif, tf[0]);
if (tf[1])
_TIFFfree(tf[1]);
_TIFFfreeExt(tif, tf[1]);
if (tf[2])
_TIFFfree(tf[2]);
_TIFFfreeExt(tif, tf[2]);
tf[0] = tf[1] = tf[2] = 0;
return 0;
}

static int
TIFFDefaultRefBlackWhite(TIFFDirectory* td)
TIFFDefaultRefBlackWhite(TIFF* tif, TIFFDirectory* td)
{
int i;

td->td_refblackwhite = (float *)_TIFFmalloc(6*sizeof (float));
td->td_refblackwhite = (float *)_TIFFmallocExt(tif, 6*sizeof (float));
if (td->td_refblackwhite == NULL)
return 0;
if (td->td_photometric == PHOTOMETRIC_YCBCR) {
Expand Down Expand Up @@ -332,7 +332,7 @@ TIFFVGetFieldDefaulted(TIFF* tif, uint32_t tag, va_list ap)
}
case TIFFTAG_TRANSFERFUNCTION:
if (!td->td_transferfunction[0] &&
!TIFFDefaultTransferFunction(td)) {
!TIFFDefaultTransferFunction(tif, td)) {
TIFFErrorExtR(tif, tif->tif_name, "No space for \"TransferFunction\" tag");
return (0);
}
Expand All @@ -343,7 +343,7 @@ TIFFVGetFieldDefaulted(TIFF* tif, uint32_t tag, va_list ap)
}
return (1);
case TIFFTAG_REFERENCEBLACKWHITE:
if (!td->td_refblackwhite && !TIFFDefaultRefBlackWhite(td))
if (!td->td_refblackwhite && !TIFFDefaultRefBlackWhite(tif, td))
return (0);
*va_arg(ap, const float **) = td->td_refblackwhite;
return (1);
Expand Down
22 changes: 11 additions & 11 deletions libtiff/tif_close.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ TIFFCleanup(TIFF* tif)
TIFFFreeDirectory(tif);

if (tif->tif_dirlistoff)
_TIFFfree(tif->tif_dirlistoff);
_TIFFfreeExt(tif, tif->tif_dirlistoff);
if (tif->tif_dirlistdirn)
_TIFFfree(tif->tif_dirlistdirn);
_TIFFfreeExt(tif, tif->tif_dirlistdirn);

/*
* Clean up client info links.
Expand All @@ -65,12 +65,12 @@ TIFFCleanup(TIFF* tif)
TIFFClientInfoLink *psLink = tif->tif_clientinfo;

tif->tif_clientinfo = psLink->next;
_TIFFfree( psLink->name );
_TIFFfree( psLink );
_TIFFfreeExt(tif, psLink->name );
_TIFFfreeExt(tif, psLink );
}

if (tif->tif_rawdata && (tif->tif_flags&TIFF_MYBUFFER))
_TIFFfree(tif->tif_rawdata);
_TIFFfreeExt(tif, tif->tif_rawdata);
if (isMapped(tif))
TIFFUnmapFileContents(tif, tif->tif_base, (toff_t)tif->tif_size);

Expand All @@ -88,26 +88,26 @@ TIFFCleanup(TIFF* tif)
* Otherwise the following tags are also freed with the first free().
*/
TIFFFieldIsAnonymous(fld)) {
_TIFFfree(fld->field_name);
_TIFFfree(fld);
_TIFFfreeExt(tif, fld->field_name);
_TIFFfreeExt(tif, fld);
}
}
}

_TIFFfree(tif->tif_fields);
_TIFFfreeExt(tif, tif->tif_fields);
}

if (tif->tif_nfieldscompat > 0) {
uint32_t i;

for (i = 0; i < tif->tif_nfieldscompat; i++) {
if (tif->tif_fieldscompat[i].allocated_size)
_TIFFfree(tif->tif_fieldscompat[i].fields);
_TIFFfreeExt(tif, tif->tif_fieldscompat[i].fields);
}
_TIFFfree(tif->tif_fieldscompat);
_TIFFfreeExt(tif, tif->tif_fieldscompat);
}

_TIFFfree(tif);
_TIFFfreeExt(NULL, tif);
}

/************************************************************************/
Expand Down
16 changes: 8 additions & 8 deletions libtiff/tif_compress.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ TIFFCodec*
TIFFRegisterCODEC(uint16_t scheme, const char* name, TIFFInitMethod init)
{
codec_t* cd = (codec_t*)
_TIFFmalloc((tmsize_t)(sizeof (codec_t) + sizeof (TIFFCodec) + strlen(name)+1));
_TIFFmallocExt(NULL, (tmsize_t)(sizeof (codec_t) + sizeof (TIFFCodec) + strlen(name)+1));

if (cd != NULL) {
cd->info = (TIFFCodec*) ((uint8_t*) cd + sizeof (codec_t));
Expand Down Expand Up @@ -228,7 +228,7 @@ TIFFUnRegisterCODEC(TIFFCodec* c)
for (pcd = &registeredCODECS; (cd = *pcd) != NULL; pcd = &cd->next)
if (cd->info == c) {
*pcd = cd->next;
_TIFFfree(cd);
_TIFFfreeExt(NULL, cd);
return;
}
TIFFErrorExt(0, "TIFFUnRegisterCODEC",
Expand Down Expand Up @@ -258,9 +258,9 @@ TIFFGetConfiguredCODECs()

for (cd = registeredCODECS; cd; cd = cd->next) {
new_codecs = (TIFFCodec *)
_TIFFrealloc(codecs, i * sizeof(TIFFCodec));
_TIFFreallocExt(NULL, codecs, i * sizeof(TIFFCodec));
if (!new_codecs) {
_TIFFfree (codecs);
_TIFFfreeExt (NULL, codecs);
return NULL;
}
codecs = new_codecs;
Expand All @@ -270,9 +270,9 @@ TIFFGetConfiguredCODECs()
for (c = _TIFFBuiltinCODECS; c->name; c++) {
if (TIFFIsCODECConfigured(c->scheme)) {
new_codecs = (TIFFCodec *)
_TIFFrealloc(codecs, i * sizeof(TIFFCodec));
_TIFFreallocExt(NULL, codecs, i * sizeof(TIFFCodec));
if (!new_codecs) {
_TIFFfree (codecs);
_TIFFfreeExt (NULL, codecs);
return NULL;
}
codecs = new_codecs;
Expand All @@ -281,9 +281,9 @@ TIFFGetConfiguredCODECs()
}
}

new_codecs = (TIFFCodec *) _TIFFrealloc(codecs, i * sizeof(TIFFCodec));
new_codecs = (TIFFCodec *) _TIFFreallocExt(NULL, codecs, i * sizeof(TIFFCodec));
if (!new_codecs) {
_TIFFfree (codecs);
_TIFFfreeExt (NULL, codecs);
return NULL;
}
codecs = new_codecs;
Expand Down
Loading

0 comments on commit 553bb4b

Please sign in to comment.