1 /* kpathsea.c: creating and freeing library instances
3 Copyright 2009, 2012 Taco Hoekwater.
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this library; if not, see <http://www.gnu.org/licenses/>. */
18 /* One big global struct, and a variable that points to it */
21 * The code freeing the strings used in this struct is enabled/disabled
22 * by KPATHSEA_CAN_FREE.
25 #include <kpathsea/config.h>
31 ret
= xcalloc(1, sizeof(kpathsea_instance
));
37 #define string_free(a) if ((a) != NULL) free((char *)(a))
40 str_llist_free (str_llist_type p
)
52 cache_free (cache_entry
*the_cache
, int cache_size
)
55 for (f
= 0; f
< cache_size
; f
++) {
56 string_free (the_cache
[f
].key
);
57 str_llist_free (the_cache
[f
].value
[0]);
61 #endif /* KPATHSEA_CAN_FREE */
63 /* Sadly, quite a lot of the freeing is not safe:
64 it seems there are literals used all over. */
66 kpathsea_finish (kpathsea kpse
)
70 kpse_format_info_type f
;
71 #endif /* KPATHSEA_CAN_FREE */
75 /* free internal stuff */
76 hash_free (kpse
->cnf_hash
);
78 hash_free (kpse
->alias_db
);
79 str_list_free (&kpse
->db_dir_list
);
80 hash_free (kpse
->link_table
);
81 cache_free (kpse
->the_cache
, kpse
->cache_length
);
82 hash_free (kpse
->map
);
83 string_free (kpse
->map_path
);
84 string_free (kpse
->elt
);
85 /*string_free (kpse->path);*/
86 if (kpse
->log_file
!= (FILE *)NULL
)
87 fclose(kpse
->log_file
);
88 string_free (kpse
->invocation_name
);
89 string_free (kpse
->invocation_short_name
);
90 string_free (kpse
->program_name
);
91 string_free (kpse
->fallback_font
);
92 string_free (kpse
->fallback_resolutions_string
);
93 if(kpse
->fallback_resolutions
!= NULL
)
94 free(kpse
->fallback_resolutions
);
95 for (i
= 0; i
!= kpse_last_format
; ++i
) {
96 f
= kpse
->format_info
[i
];
98 string_free (f
.override_path
);
99 string_free (f
.client_path
);
100 /*string_free (f.cnf_path);*/
103 if (kpse
->missfont
!= (FILE *)NULL
)
104 fclose (kpse
->missfont
);
106 for (i
= 0; i
< (int)kpse
->expansion_len
; i
++) {
107 string_free (kpse
->expansions
[i
].var
);
109 free (kpse
->expansions
);
110 if (kpse
->saved_env
!= NULL
) {
111 for (i
= 0; i
!= kpse
->saved_count
; ++i
)
112 string_free (kpse
->saved_env
[i
]);
113 free (kpse
->saved_env
);
115 #endif /* KPATHSEA_CAN_FREE */
116 #if defined(WIN32) || defined(__CYGWIN__)
117 if (kpse
->suffixlist
!= NULL
) {
119 for (p
= kpse
->suffixlist
; *p
; p
++)
121 free (kpse
->suffixlist
);
122 kpse
->suffixlist
= NULL
;
124 #endif /* WIN32 || __CYGWIN__ */
125 #if defined (KPSE_COMPAT_API)
126 if (kpse
== kpse_def
)
133 #if defined (KPSE_COMPAT_API)
135 kpathsea_instance kpse_def_inst
;
136 kpathsea kpse_def
= &kpse_def_inst
;
138 #endif /* KPSE_COMPAT_API */