Ensure that tjFree() is used for any JPEG buffers that might have been dynamically allocated by the compress/transform functions. To keep things simple, we use tjAlloc() for the statically-allocated buffer as well, so that tjFree() can always be used to free the buffer, regardless of whether it was allocated by tjbench or by the TurboJPEG library. This fixes crashes that occurred on Windows when running tjunittest or tjbench with the -alloc flag.

git-svn-id: svn+ssh://svn.code.sf.net/p/libjpeg-turbo/code/branches/1.3.x@1384 632fc199-4ca6-4c93-a231-07263d6284db
This commit is contained in:
DRC
2014-08-22 19:59:51 +00:00
parent 7930a77eaa
commit 578c3f67d7
2 changed files with 8 additions and 8 deletions

View File

@@ -353,7 +353,7 @@ int dotest(unsigned char *srcbuf, int w, int h, int subsamp, int jpegqual,
if((flags&TJFLAG_NOREALLOC)!=0)
for(i=0; i<ntilesw*ntilesh; i++)
{
if((jpegbuf[i]=(unsigned char *)malloc(tjBufSize(tilew, tileh,
if((jpegbuf[i]=(unsigned char *)tjAlloc(tjBufSize(tilew, tileh,
subsamp)))==NULL)
_throwunix("allocating JPEG tiles");
}
@@ -436,7 +436,7 @@ int dotest(unsigned char *srcbuf, int w, int h, int subsamp, int jpegqual,
for(i=0; i<ntilesw*ntilesh; i++)
{
if(jpegbuf[i]) free(jpegbuf[i]); jpegbuf[i]=NULL;
if(jpegbuf[i]) tjFree(jpegbuf[i]); jpegbuf[i]=NULL;
}
free(jpegbuf); jpegbuf=NULL;
free(jpegsize); jpegsize=NULL;
@@ -450,7 +450,7 @@ int dotest(unsigned char *srcbuf, int w, int h, int subsamp, int jpegqual,
{
for(i=0; i<ntilesw*ntilesh; i++)
{
if(jpegbuf[i]) free(jpegbuf[i]); jpegbuf[i]=NULL;
if(jpegbuf[i]) tjFree(jpegbuf[i]); jpegbuf[i]=NULL;
}
free(jpegbuf); jpegbuf=NULL;
}
@@ -524,7 +524,7 @@ int dodecomptest(char *filename)
if((flags&TJFLAG_NOREALLOC)!=0 || !dotile)
for(i=0; i<ntilesw*ntilesh; i++)
{
if((jpegbuf[i]=(unsigned char *)malloc(tjBufSize(tilew, tileh,
if((jpegbuf[i]=(unsigned char *)tjAlloc(tjBufSize(tilew, tileh,
subsamp)))==NULL)
_throwunix("allocating JPEG tiles");
}
@@ -583,7 +583,7 @@ int dodecomptest(char *filename)
t[tile].customFilter=customFilter;
if(t[tile].options&TJXOPT_NOOUTPUT && jpegbuf[tile])
{
free(jpegbuf[tile]); jpegbuf[tile]=NULL;
tjFree(jpegbuf[tile]); jpegbuf[tile]=NULL;
}
}
}
@@ -638,7 +638,7 @@ int dodecomptest(char *filename)
for(i=0; i<ntilesw*ntilesh; i++)
{
free(jpegbuf[i]); jpegbuf[i]=NULL;
tjFree(jpegbuf[i]); jpegbuf[i]=NULL;
}
free(jpegbuf); jpegbuf=NULL;
if(jpegsize) {free(jpegsize); jpegsize=NULL;}
@@ -652,7 +652,7 @@ int dodecomptest(char *filename)
{
for(i=0; i<ntilesw*ntilesh; i++)
{
if(jpegbuf[i]) free(jpegbuf[i]); jpegbuf[i]=NULL;
if(jpegbuf[i]) tjFree(jpegbuf[i]); jpegbuf[i]=NULL;
}
free(jpegbuf); jpegbuf=NULL;
}

View File

@@ -613,7 +613,7 @@ void bufSizeTest(void)
bailout:
if(srcBuf) free(srcBuf);
if(dstBuf) free(dstBuf);
if(dstBuf) tjFree(dstBuf);
if(handle) tjDestroy(handle);
}