Skip to content

Commit 00607ec

Browse files
committed
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.
1 parent fdf8903 commit 00607ec

7 files changed

Lines changed: 19 additions & 18 deletions

File tree

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ best of our understanding.
9191
The Modified (3-clause) BSD License
9292
===================================
9393

94-
Copyright (C)2009-2019 D. R. Commander. All Rights Reserved.
94+
Copyright (C)2009-2020 D. R. Commander. All Rights Reserved.
9595
Copyright (C)2015 Viktor Szathmáry. All Rights Reserved.
9696

9797
Redistribution and use in source and binary forms, with or without

doc/html/group___turbo_j_p_e_g.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2078,7 +2078,7 @@ <h2 class="groupheader">Function Documentation</h2>
20782078
<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>
20792079
<dl class="params"><dt>Parameters</dt><dd>
20802080
<table class="params">
2081-
<tr><td class="paramname">buffer</td><td>address of the buffer to free</td></tr>
2081+
<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>
20822082
</table>
20832083
</dd>
20842084
</dl>

jversion.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This file was part of the Independent JPEG Group's software:
55
* Copyright (C) 1991-2012, Thomas G. Lane, Guido Vollbeding.
66
* libjpeg-turbo Modifications:
7-
* Copyright (C) 2010, 2012-2019, D. R. Commander.
7+
* Copyright (C) 2010, 2012-2020, D. R. Commander.
88
* For conditions of distribution and use, see the accompanying README.ijg
99
* file.
1010
*
@@ -36,7 +36,7 @@
3636
*/
3737

3838
#define JCOPYRIGHT \
39-
"Copyright (C) 2009-2019 D. R. Commander\n" \
39+
"Copyright (C) 2009-2020 D. R. Commander\n" \
4040
"Copyright (C) 2011-2016 Siarhei Siamashka\n" \
4141
"Copyright (C) 2015-2016, 2018 Matthieu Darbois\n" \
4242
"Copyright (C) 2015 Intel Corporation\n" \
@@ -49,4 +49,4 @@
4949
"Copyright (C) 1991-2016 Thomas G. Lane, Guido Vollbeding"
5050

5151
#define JCOPYRIGHT_SHORT \
52-
"Copyright (C) 1991-2019 The libjpeg-turbo Project and many others"
52+
"Copyright (C) 1991-2020 The libjpeg-turbo Project and many others"

tjbench.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ static int fullTest(unsigned char *srcBuf, int w, int h, int subsamp,
489489
} else if (quiet == 1) printf("N/A\n");
490490

491491
for (i = 0; i < ntilesw * ntilesh; i++) {
492-
if (jpegBuf[i]) tjFree(jpegBuf[i]);
492+
tjFree(jpegBuf[i]);
493493
jpegBuf[i] = NULL;
494494
}
495495
free(jpegBuf); jpegBuf = NULL;
@@ -505,7 +505,7 @@ static int fullTest(unsigned char *srcBuf, int w, int h, int subsamp,
505505
if (file) fclose(file);
506506
if (jpegBuf) {
507507
for (i = 0; i < ntilesw * ntilesh; i++)
508-
if (jpegBuf[i]) tjFree(jpegBuf[i]);
508+
tjFree(jpegBuf[i]);
509509
}
510510
free(jpegBuf);
511511
free(yuvBuf);
@@ -699,7 +699,7 @@ static int decompTest(char *fileName)
699699
}
700700
} else {
701701
if (quiet == 1) printf("N/A N/A ");
702-
if (jpegBuf[0]) tjFree(jpegBuf[0]);
702+
tjFree(jpegBuf[0]);
703703
jpegBuf[0] = NULL;
704704
decompsrc = 1;
705705
}
@@ -714,7 +714,7 @@ static int decompTest(char *fileName)
714714
} else if (quiet == 1) printf("N/A\n");
715715

716716
for (i = 0; i < ntilesw * ntilesh; i++) {
717-
if (jpegBuf[i]) tjFree(jpegBuf[i]);
717+
tjFree(jpegBuf[i]);
718718
jpegBuf[i] = NULL;
719719
}
720720
free(jpegBuf); jpegBuf = NULL;
@@ -727,7 +727,7 @@ static int decompTest(char *fileName)
727727
if (file) fclose(file);
728728
if (jpegBuf) {
729729
for (i = 0; i < ntilesw * ntilesh; i++)
730-
if (jpegBuf[i]) tjFree(jpegBuf[i]);
730+
tjFree(jpegBuf[i]);
731731
}
732732
free(jpegBuf);
733733
free(jpegSize);
@@ -1022,6 +1022,6 @@ int main(int argc, char *argv[])
10221022
}
10231023

10241024
bailout:
1025-
if (srcBuf) tjFree(srcBuf);
1025+
tjFree(srcBuf);
10261026
return retval;
10271027
}

tjexample.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,9 +388,9 @@ int main(int argc, char **argv)
388388
}
389389

390390
bailout:
391-
if (imgBuf) tjFree(imgBuf);
391+
tjFree(imgBuf);
392392
if (tjInstance) tjDestroy(tjInstance);
393-
if (jpegBuf) tjFree(jpegBuf);
393+
tjFree(jpegBuf);
394394
if (jpegFile) fclose(jpegFile);
395395
return retval;
396396
}

tjunittest.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ static void doTest(int w, int h, const int *formats, int nformats, int subsamp,
550550
bailout:
551551
if (chandle) tjDestroy(chandle);
552552
if (dhandle) tjDestroy(dhandle);
553-
if (dstBuf) tjFree(dstBuf);
553+
tjFree(dstBuf);
554554
}
555555

556556

@@ -666,7 +666,7 @@ static void bufSizeTest(void)
666666

667667
bailout:
668668
free(srcBuf);
669-
if (dstBuf) tjFree(dstBuf);
669+
tjFree(dstBuf);
670670
if (handle) tjDestroy(handle);
671671
}
672672

@@ -839,7 +839,7 @@ static int doBmpTest(const char *ext, int width, int align, int height, int pf,
839839
unlink(filename);
840840

841841
bailout:
842-
if (buf) tjFree(buf);
842+
tjFree(buf);
843843
if (exitStatus < 0) return exitStatus;
844844
return retval;
845845
}

turbojpeg.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C)2009-2015, 2017 D. R. Commander. All Rights Reserved.
2+
* Copyright (C)2009-2015, 2017, 2020 D. R. Commander. All Rights Reserved.
33
*
44
* Redistribution and use in source and binary forms, with or without
55
* modification, are permitted provided that the following conditions are met:
@@ -1636,7 +1636,8 @@ DLLEXPORT int tjSaveImage(const char *filename, unsigned char *buffer,
16361636
* (re)allocated by the compression and transform functions or that were
16371637
* manually allocated using #tjAlloc().
16381638
*
1639-
* @param buffer address of the buffer to free
1639+
* @param buffer address of the buffer to free. If the address is NULL, then
1640+
* this function has no effect.
16401641
*
16411642
* @sa tjAlloc()
16421643
*/

0 commit comments

Comments
 (0)