/src/ghostpdl/tiff/libtiff/tif_close.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (c) 1988-1997 Sam Leffler |
3 | | * Copyright (c) 1991-1997 Silicon Graphics, Inc. |
4 | | * |
5 | | * Permission to use, copy, modify, distribute, and sell this software and |
6 | | * its documentation for any purpose is hereby granted without fee, provided |
7 | | * that (i) the above copyright notices and this permission notice appear in |
8 | | * all copies of the software and related documentation, and (ii) the names of |
9 | | * Sam Leffler and Silicon Graphics may not be used in any advertising or |
10 | | * publicity relating to the software without the specific, prior written |
11 | | * permission of Sam Leffler and Silicon Graphics. |
12 | | * |
13 | | * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, |
14 | | * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY |
15 | | * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. |
16 | | * |
17 | | * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR |
18 | | * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, |
19 | | * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, |
20 | | * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF |
21 | | * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE |
22 | | * OF THIS SOFTWARE. |
23 | | */ |
24 | | |
25 | | /* |
26 | | * TIFF Library. |
27 | | */ |
28 | | #include "tiffiop.h" |
29 | | #include <string.h> |
30 | | |
31 | | /************************************************************************/ |
32 | | /* TIFFCleanup() */ |
33 | | /************************************************************************/ |
34 | | |
35 | | /** |
36 | | * Auxiliary function to free the TIFF structure. Given structure will be |
37 | | * completely freed, so you should save opened file handle and pointer |
38 | | * to the close procedure in external variables before calling |
39 | | * _TIFFCleanup(), if you will need these ones to close the file. |
40 | | * |
41 | | * @param tif A TIFF pointer. |
42 | | */ |
43 | | |
44 | | void |
45 | | TIFFCleanup(TIFF* tif) |
46 | 2.19k | { |
47 | | /* |
48 | | * Flush buffered data and directory (if dirty). |
49 | | */ |
50 | 2.19k | if (tif->tif_mode != O_RDONLY) |
51 | 2.19k | TIFFFlush(tif); |
52 | 2.19k | (*tif->tif_cleanup)(tif); |
53 | 2.19k | TIFFFreeDirectory(tif); |
54 | | |
55 | 2.19k | if (tif->tif_dirlist) |
56 | 0 | _TIFFfree(tif->tif_dirlist); |
57 | | |
58 | | /* |
59 | | * Clean up client info links. |
60 | | */ |
61 | 2.19k | while( tif->tif_clientinfo ) |
62 | 0 | { |
63 | 0 | TIFFClientInfoLink *psLink = tif->tif_clientinfo; |
64 | |
|
65 | 0 | tif->tif_clientinfo = psLink->next; |
66 | 0 | _TIFFfree( psLink->name ); |
67 | 0 | _TIFFfree( psLink ); |
68 | 0 | } |
69 | | |
70 | 2.19k | if (tif->tif_rawdata && (tif->tif_flags&TIFF_MYBUFFER)) |
71 | 0 | _TIFFfree(tif->tif_rawdata); |
72 | 2.19k | if (isMapped(tif)) |
73 | 0 | TIFFUnmapFileContents(tif, tif->tif_base, (toff_t)tif->tif_size); |
74 | | |
75 | | /* |
76 | | * Clean up custom fields. |
77 | | */ |
78 | 2.19k | if (tif->tif_fields && tif->tif_nfields > 0) { |
79 | 2.19k | uint32_t i; |
80 | | |
81 | 335k | for (i = 0; i < tif->tif_nfields; i++) { |
82 | 333k | TIFFField *fld = tif->tif_fields[i]; |
83 | 333k | if (fld->field_bit == FIELD_CUSTOM && |
84 | 333k | strncmp("Tag ", fld->field_name, 4) == 0) { |
85 | 0 | _TIFFfree(fld->field_name); |
86 | 0 | _TIFFfree(fld); |
87 | 0 | } |
88 | 333k | } |
89 | | |
90 | 2.19k | _TIFFfree(tif->tif_fields); |
91 | 2.19k | } |
92 | | |
93 | 2.19k | if (tif->tif_nfieldscompat > 0) { |
94 | 0 | uint32_t i; |
95 | |
|
96 | 0 | for (i = 0; i < tif->tif_nfieldscompat; i++) { |
97 | 0 | if (tif->tif_fieldscompat[i].allocated_size) |
98 | 0 | _TIFFfree(tif->tif_fieldscompat[i].fields); |
99 | 0 | } |
100 | 0 | _TIFFfree(tif->tif_fieldscompat); |
101 | 0 | } |
102 | | |
103 | 2.19k | _TIFFfree(tif); |
104 | 2.19k | } |
105 | | |
106 | | /************************************************************************/ |
107 | | /* TIFFClose() */ |
108 | | /************************************************************************/ |
109 | | |
110 | | /** |
111 | | * Close a previously opened TIFF file. |
112 | | * |
113 | | * TIFFClose closes a file that was previously opened with TIFFOpen(). |
114 | | * Any buffered data are flushed to the file, including the contents of |
115 | | * the current directory (if modified); and all resources are reclaimed. |
116 | | * |
117 | | * @param tif A TIFF pointer. |
118 | | */ |
119 | | |
120 | | void |
121 | | TIFFClose(TIFF* tif) |
122 | 0 | { |
123 | 0 | TIFFCloseProc closeproc = tif->tif_closeproc; |
124 | 0 | thandle_t fd = tif->tif_clientdata; |
125 | |
|
126 | 0 | TIFFCleanup(tif); |
127 | 0 | (void) (*closeproc)(fd); |
128 | 0 | } |
129 | | |
130 | | /* vim: set ts=8 sts=8 sw=8 noet: */ |
131 | | |
132 | | /* |
133 | | * Local Variables: |
134 | | * mode: c |
135 | | * c-basic-offset: 8 |
136 | | * fill-column: 78 |
137 | | * End: |
138 | | */ |