LibTIFF 4.7.2
TIFF library public API and implementation reference
Loading...
Searching...
No Matches
tif_close.c
Go to the documentation of this file.
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 */
33#include "tiffiop.h"
34#include <string.h>
35
36/************************************************************************/
37/* TIFFCleanup() */
38/************************************************************************/
39
40void TIFFCleanup(TIFF *tif)
41{
42 /*
43 * Flush buffered data and directory (if dirty).
44 */
45 if (tif->tif_mode != O_RDONLY)
46 TIFFFlush(tif);
48
50
51 /*
52 * Clean up client info links.
53 */
54 while (tif->tif_clientinfo)
55 {
57
58 tif->tif_clientinfo = psLink->next;
59 _TIFFfreeExt(tif, psLink->name);
60 _TIFFfreeExt(tif, psLink);
61 }
62
63 if (tif->tif_rawdata && (tif->tif_flags & TIFF_MYBUFFER))
64 {
65 _TIFFfreeExt(tif, tif->tif_rawdata);
66 tif->tif_rawdata = NULL;
67 tif->tif_rawdatasize = 0;
68 }
69 if (isMapped(tif))
71
72 /*
73 * Clean up custom fields.
74 */
75 if (tif->tif_fields && tif->tif_nfields > 0)
76 {
77 uint32_t i;
78
79 for (i = 0; i < tif->tif_nfields; i++)
80 {
81 TIFFField *fld = tif->tif_fields[i];
82 if (fld->field_name != NULL)
83 {
84 if (fld->field_bit == FIELD_CUSTOM &&
85 /* caution: tif_fields[i] must not be the beginning of a
86 * fields-array. Otherwise the following tags are also freed
87 * with the first free().
88 */
90 {
91 _TIFFfreeExt(tif, (void *)fld->field_name);
92 _TIFFfreeExt(tif, fld);
93 }
94 }
95 }
96
97 _TIFFfreeExt(tif, tif->tif_fields);
98 }
99
100 if (tif->tif_nfieldscompat > 0)
101 {
102 uint32_t i;
103
104 for (i = 0; i < tif->tif_nfieldscompat; i++)
105 {
108 }
110 }
111
112 if (tif->tif_cur_cumulated_mem_alloc != 0)
113 {
114 TIFFErrorExtR(tif, "TIFFCleanup",
115 "tif_cur_cumulated_mem_alloc = %" PRIu64 " whereas it "
116 "should be 0",
117 (uint64_t)tif->tif_cur_cumulated_mem_alloc);
118 }
119
120 _TIFFfreeExt(NULL, tif);
121}
122
123/************************************************************************/
124/* _TIFFCleanupIFDOffsetAndNumberMaps() */
125/************************************************************************/
126
140
141/************************************************************************/
142/* TIFFClose() */
143/************************************************************************/
144
145void TIFFClose(TIFF *tif)
146{
147 if (tif != NULL)
148 {
149 TIFFCloseProc closeproc = tif->tif_closeproc;
150 thandle_t fd = tif->tif_clientdata;
151
152 TIFFCleanup(tif);
153 (void)(*closeproc)(fd);
154 }
155}
void TIFFHashSetDestroy(TIFFHashSet *set)
Release a hash set and dispose its live elements if configured.
void _TIFFCleanupIFDOffsetAndNumberMaps(TIFF *tif)
Release a handle's directory-offset/index lookup maps.
Definition tif_close.c:127
void _TIFFfreeExt(TIFF *tif, void *p)
Release a handle-aware allocation and its payload charge.
Definition tif_open.c:301
#define TIFF_MYBUFFER
Mark a raw buffer owned and released by the handle.
Definition tiffiop.h:451
#define TIFFUnmapFileContents(tif, addr, size)
Invoke the handle's client unmapping callback.
Definition tiffiop.h:977
#define isMapped(tif)
Test whether TIFF_MAPPED is set on a handle.
Definition tiffiop.h:845
#define FIELD_CUSTOM
Identify a field stored through the custom-metadata mechanism.
Definition tiffio.h:1316
void TIFFErrorExtR(TIFF *tif, const char *module, const char *fmt,...)
Dispatch a error diagnostic to the configured handlers.
Definition tif_error.c:112
void TIFFFreeDirectory(TIFF *tif)
Release the current directory's owned values and codec state.
Definition tif_dir.c:2165
int TIFFFieldIsAnonymous(const TIFFField *fip)
Test whether a field was registered as an unknown tag.
int(* TIFFCloseProc)(thandle_t fd)
Release a client I/O resource or its adapter context.
Definition tiffio.h:951
void TIFFClose(TIFF *tif)
Release a TIFF handle and invoke its client close callback.
Definition tif_close.c:145
int TIFFFlush(TIFF *tif)
Flush pending image data and dirty directory information.
Definition tif_flush.c:35
void TIFFCleanup(TIFF *tif)
Release library state without invoking the client close callback.
Definition tif_close.c:40
uint64_t toff_t
Represent an unsigned file byte offset independently of off_t.
Definition tiffio.h:94
void * thandle_t
Carry an opaque client I/O context through library callbacks.
Definition tiffio.h:161
uint32_t allocated_size
Descriptor capacity when owned; zero identifies a static schema.
Definition tif_dir.h:970
TIFFField * fields
Descriptor array; static/borrowed or owned according to allocated_size and creator.
Definition tif_dir.h:978
Describe a field's file type and internal argument contract.
Definition tif_dir.h:993
const char * field_name
Borrowed or anonymous-owned null-terminated name; must remain live while used.
Definition tif_dir.h:1038
unsigned short field_bit
FIELD_* presence index; FIELD_CUSTOM shares storage through the custom list.
Definition tif_dir.h:1023
Link a named client-data association to a TIFF handle.
Definition tiffiop.h:148
struct client_info * next
Next handle-owned association node, or NULL.
Definition tiffiop.h:150
char * name
Owned copy of the null-terminated association name.
Definition tiffiop.h:154
Hold private state for one open TIFF library instance.
Definition tiffiop.h:389
TIFFHashSet * tif_map_dir_number_to_offset
Handle-managed directory-index-to-offset lookup map.
Definition tiffiop.h:566
size_t tif_nfields
Number of entries in tif_fields.
Definition tiffiop.h:735
TIFFCloseProc tif_closeproc
Client I/O close callback.
Definition tiffiop.h:720
TIFFClientInfoLink * tif_clientinfo
Head of the owned named-association list; payloads remain borrowed.
Definition tiffiop.h:747
TIFFField ** tif_fields
Owned sorted array of field pointers; descriptors have mixed ownership.
Definition tiffiop.h:733
TIFFHashSet * tif_map_dir_offset_to_number
Handle-managed directory-offset-to-index lookup map.
Definition tiffiop.h:564
thandle_t tif_clientdata
Client I/O context passed unchanged to the I/O callbacks.
Definition tiffiop.h:712
tmsize_t tif_size
Mapped-file region length in bytes.
Definition tiffiop.h:705
tmsize_t tif_cur_cumulated_mem_alloc
Current tracked allocation total in bytes.
Definition tiffiop.h:775
uint8_t * tif_rawdata
Raw buffer; ownership/mapping follow TIFF_MYBUFFER and TIFF_BUFFERMMAP.
Definition tiffiop.h:681
tmsize_t tif_rawdatasize
Raw-buffer capacity in bytes; kept in step with tif_rawdata, including zero whenever tif_rawdata is N...
Definition tiffiop.h:686
uint32_t tif_flags
Bitmask combining the TIFF_* handle-state flags declared below.
Definition tiffiop.h:404
size_t tif_nfieldscompat
Number of entries in tif_fieldscompat.
Definition tiffiop.h:753
int tif_mode
Current access mode using the O_* constants.
Definition tiffiop.h:400
TIFFFieldArray * tif_fieldscompat
Owned array of legacy field-registration batches.
Definition tiffiop.h:751
uint8_t * tif_base
Mapped-file base provided by tif_mapproc; released through tif_unmapproc by TIFFCleanup() only while ...
Definition tiffiop.h:703
Declare private library state, callbacks, and implementation helpers.