Eliminate unnecessary NULL checks before tjFree()
+ document that tjFree() accepts NULL pointers without complaint. Effectively, it has had that behavior all along, but the API does not guarantee that tjFree() will be implemented with free() behind the scenes, so it's best to formalize the behavior.
This commit is contained in:
@@ -91,7 +91,7 @@ best of our understanding.
|
|||||||
The Modified (3-clause) BSD License
|
The Modified (3-clause) BSD License
|
||||||
===================================
|
===================================
|
||||||
|
|
||||||
Copyright (C)2009-2019 D. R. Commander. All Rights Reserved.
|
Copyright (C)2009-2020 D. R. Commander. All Rights Reserved.
|
||||||
Copyright (C)2015 Viktor Szathmáry. All Rights Reserved.
|
Copyright (C)2015 Viktor Szathmáry. All Rights Reserved.
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
|||||||
@@ -2078,7 +2078,7 @@ If you choose option 1, <code>*jpegSize</code> should be set to the size of your
|
|||||||
<p>You should always use this function to free JPEG destination buffer(s) that were automatically (re)allocated by the compression and transform functions or that were manually allocated using <a class="el" href="group___turbo_j_p_e_g.html#gaec627dd4c5f30b7a775a7aea3bec5d83" title="Allocate an image buffer for use with TurboJPEG.">tjAlloc()</a>.</p>
|
<p>You should always use this function to free JPEG destination buffer(s) that were automatically (re)allocated by the compression and transform functions or that were manually allocated using <a class="el" href="group___turbo_j_p_e_g.html#gaec627dd4c5f30b7a775a7aea3bec5d83" title="Allocate an image buffer for use with TurboJPEG.">tjAlloc()</a>.</p>
|
||||||
<dl class="params"><dt>Parameters</dt><dd>
|
<dl class="params"><dt>Parameters</dt><dd>
|
||||||
<table class="params">
|
<table class="params">
|
||||||
<tr><td class="paramname">buffer</td><td>address of the buffer to free</td></tr>
|
<tr><td class="paramname">buffer</td><td>address of the buffer to free. If the address is NULL, then this function has no effect.</td></tr>
|
||||||
</table>
|
</table>
|
||||||
</dd>
|
</dd>
|
||||||
</dl>
|
</dl>
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
* This file was part of the Independent JPEG Group's software:
|
* This file was part of the Independent JPEG Group's software:
|
||||||
* Copyright (C) 1991-2012, Thomas G. Lane, Guido Vollbeding.
|
* Copyright (C) 1991-2012, Thomas G. Lane, Guido Vollbeding.
|
||||||
* libjpeg-turbo Modifications:
|
* libjpeg-turbo Modifications:
|
||||||
* Copyright (C) 2010, 2012-2019, D. R. Commander.
|
* Copyright (C) 2010, 2012-2020, D. R. Commander.
|
||||||
* For conditions of distribution and use, see the accompanying README.ijg
|
* For conditions of distribution and use, see the accompanying README.ijg
|
||||||
* file.
|
* file.
|
||||||
*
|
*
|
||||||
@@ -36,7 +36,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#define JCOPYRIGHT \
|
#define JCOPYRIGHT \
|
||||||
"Copyright (C) 2009-2019 D. R. Commander\n" \
|
"Copyright (C) 2009-2020 D. R. Commander\n" \
|
||||||
"Copyright (C) 2011-2016 Siarhei Siamashka\n" \
|
"Copyright (C) 2011-2016 Siarhei Siamashka\n" \
|
||||||
"Copyright (C) 2015-2016, 2018 Matthieu Darbois\n" \
|
"Copyright (C) 2015-2016, 2018 Matthieu Darbois\n" \
|
||||||
"Copyright (C) 2015 Intel Corporation\n" \
|
"Copyright (C) 2015 Intel Corporation\n" \
|
||||||
@@ -49,4 +49,4 @@
|
|||||||
"Copyright (C) 1991-2016 Thomas G. Lane, Guido Vollbeding"
|
"Copyright (C) 1991-2016 Thomas G. Lane, Guido Vollbeding"
|
||||||
|
|
||||||
#define JCOPYRIGHT_SHORT \
|
#define JCOPYRIGHT_SHORT \
|
||||||
"Copyright (C) 1991-2019 The libjpeg-turbo Project and many others"
|
"Copyright (C) 1991-2020 The libjpeg-turbo Project and many others"
|
||||||
|
|||||||
12
tjbench.c
12
tjbench.c
@@ -489,7 +489,7 @@ static int fullTest(unsigned char *srcBuf, int w, int h, int subsamp,
|
|||||||
} else if (quiet == 1) printf("N/A\n");
|
} else if (quiet == 1) printf("N/A\n");
|
||||||
|
|
||||||
for (i = 0; i < ntilesw * ntilesh; i++) {
|
for (i = 0; i < ntilesw * ntilesh; i++) {
|
||||||
if (jpegBuf[i]) tjFree(jpegBuf[i]);
|
tjFree(jpegBuf[i]);
|
||||||
jpegBuf[i] = NULL;
|
jpegBuf[i] = NULL;
|
||||||
}
|
}
|
||||||
free(jpegBuf); jpegBuf = NULL;
|
free(jpegBuf); jpegBuf = NULL;
|
||||||
@@ -505,7 +505,7 @@ bailout:
|
|||||||
if (file) fclose(file);
|
if (file) fclose(file);
|
||||||
if (jpegBuf) {
|
if (jpegBuf) {
|
||||||
for (i = 0; i < ntilesw * ntilesh; i++)
|
for (i = 0; i < ntilesw * ntilesh; i++)
|
||||||
if (jpegBuf[i]) tjFree(jpegBuf[i]);
|
tjFree(jpegBuf[i]);
|
||||||
}
|
}
|
||||||
free(jpegBuf);
|
free(jpegBuf);
|
||||||
free(yuvBuf);
|
free(yuvBuf);
|
||||||
@@ -699,7 +699,7 @@ static int decompTest(char *fileName)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (quiet == 1) printf("N/A N/A ");
|
if (quiet == 1) printf("N/A N/A ");
|
||||||
if (jpegBuf[0]) tjFree(jpegBuf[0]);
|
tjFree(jpegBuf[0]);
|
||||||
jpegBuf[0] = NULL;
|
jpegBuf[0] = NULL;
|
||||||
decompsrc = 1;
|
decompsrc = 1;
|
||||||
}
|
}
|
||||||
@@ -714,7 +714,7 @@ static int decompTest(char *fileName)
|
|||||||
} else if (quiet == 1) printf("N/A\n");
|
} else if (quiet == 1) printf("N/A\n");
|
||||||
|
|
||||||
for (i = 0; i < ntilesw * ntilesh; i++) {
|
for (i = 0; i < ntilesw * ntilesh; i++) {
|
||||||
if (jpegBuf[i]) tjFree(jpegBuf[i]);
|
tjFree(jpegBuf[i]);
|
||||||
jpegBuf[i] = NULL;
|
jpegBuf[i] = NULL;
|
||||||
}
|
}
|
||||||
free(jpegBuf); jpegBuf = NULL;
|
free(jpegBuf); jpegBuf = NULL;
|
||||||
@@ -727,7 +727,7 @@ bailout:
|
|||||||
if (file) fclose(file);
|
if (file) fclose(file);
|
||||||
if (jpegBuf) {
|
if (jpegBuf) {
|
||||||
for (i = 0; i < ntilesw * ntilesh; i++)
|
for (i = 0; i < ntilesw * ntilesh; i++)
|
||||||
if (jpegBuf[i]) tjFree(jpegBuf[i]);
|
tjFree(jpegBuf[i]);
|
||||||
}
|
}
|
||||||
free(jpegBuf);
|
free(jpegBuf);
|
||||||
free(jpegSize);
|
free(jpegSize);
|
||||||
@@ -1022,6 +1022,6 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
bailout:
|
bailout:
|
||||||
if (srcBuf) tjFree(srcBuf);
|
tjFree(srcBuf);
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -388,9 +388,9 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
bailout:
|
bailout:
|
||||||
if (imgBuf) tjFree(imgBuf);
|
tjFree(imgBuf);
|
||||||
if (tjInstance) tjDestroy(tjInstance);
|
if (tjInstance) tjDestroy(tjInstance);
|
||||||
if (jpegBuf) tjFree(jpegBuf);
|
tjFree(jpegBuf);
|
||||||
if (jpegFile) fclose(jpegFile);
|
if (jpegFile) fclose(jpegFile);
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -550,7 +550,7 @@ static void doTest(int w, int h, const int *formats, int nformats, int subsamp,
|
|||||||
bailout:
|
bailout:
|
||||||
if (chandle) tjDestroy(chandle);
|
if (chandle) tjDestroy(chandle);
|
||||||
if (dhandle) tjDestroy(dhandle);
|
if (dhandle) tjDestroy(dhandle);
|
||||||
if (dstBuf) tjFree(dstBuf);
|
tjFree(dstBuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -666,7 +666,7 @@ static void bufSizeTest(void)
|
|||||||
|
|
||||||
bailout:
|
bailout:
|
||||||
free(srcBuf);
|
free(srcBuf);
|
||||||
if (dstBuf) tjFree(dstBuf);
|
tjFree(dstBuf);
|
||||||
if (handle) tjDestroy(handle);
|
if (handle) tjDestroy(handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -839,7 +839,7 @@ static int doBmpTest(const char *ext, int width, int align, int height, int pf,
|
|||||||
unlink(filename);
|
unlink(filename);
|
||||||
|
|
||||||
bailout:
|
bailout:
|
||||||
if (buf) tjFree(buf);
|
tjFree(buf);
|
||||||
if (exitStatus < 0) return exitStatus;
|
if (exitStatus < 0) return exitStatus;
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C)2009-2015, 2017 D. R. Commander. All Rights Reserved.
|
* Copyright (C)2009-2015, 2017, 2020 D. R. Commander. All Rights Reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* modification, are permitted provided that the following conditions are met:
|
||||||
@@ -1636,7 +1636,8 @@ DLLEXPORT int tjSaveImage(const char *filename, unsigned char *buffer,
|
|||||||
* (re)allocated by the compression and transform functions or that were
|
* (re)allocated by the compression and transform functions or that were
|
||||||
* manually allocated using #tjAlloc().
|
* manually allocated using #tjAlloc().
|
||||||
*
|
*
|
||||||
* @param buffer address of the buffer to free
|
* @param buffer address of the buffer to free. If the address is NULL, then
|
||||||
|
* this function has no effect.
|
||||||
*
|
*
|
||||||
* @sa tjAlloc()
|
* @sa tjAlloc()
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user