Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (C) Internet Systems Consortium, Inc. ("ISC") |
3 | | * |
4 | | * SPDX-License-Identifier: MPL-2.0 |
5 | | * |
6 | | * This Source Code Form is subject to the terms of the Mozilla Public |
7 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
8 | | * file, you can obtain one at https://mozilla.org/MPL/2.0/. |
9 | | * |
10 | | * See the COPYRIGHT file distributed with this work for additional |
11 | | * information regarding copyright ownership. |
12 | | */ |
13 | | |
14 | | #include <isc/mem.h> |
15 | | #include <isc/util.h> |
16 | | #include <isc/xml.h> |
17 | | |
18 | | #ifdef HAVE_LIBXML2 |
19 | | #include <libxml/parser.h> |
20 | | #include <libxml/xmlversion.h> |
21 | | |
22 | | #ifndef LIBXML_HAS_DEPRECATED_MEMORY_ALLOCATION_FUNCTIONS |
23 | | static isc_mem_t *isc__xml_mctx = NULL; |
24 | | |
25 | | static void * |
26 | | isc__xml_malloc(size_t size) { |
27 | | return isc_mem_allocate(isc__xml_mctx, size); |
28 | | } |
29 | | |
30 | | static void * |
31 | | isc__xml_realloc(void *ptr, size_t size) { |
32 | | return isc_mem_reallocate(isc__xml_mctx, ptr, size); |
33 | | } |
34 | | |
35 | | static char * |
36 | | isc__xml_strdup(const char *str) { |
37 | | return isc_mem_strdup(isc__xml_mctx, str); |
38 | | } |
39 | | |
40 | | static void |
41 | | isc__xml_free(void *ptr) { |
42 | | if (ptr == NULL) { |
43 | | return; |
44 | | } |
45 | | isc_mem_free(isc__xml_mctx, ptr); |
46 | | } |
47 | | |
48 | | #endif /* !LIBXML_HAS_DEPRECATED_MEMORY_ALLOCATION_FUNCTIONS) */ |
49 | | #endif /* HAVE_LIBXML2 */ |
50 | | |
51 | | void |
52 | 22 | isc__xml_initialize(void) { |
53 | | #ifdef HAVE_LIBXML2 |
54 | | #ifndef LIBXML_HAS_DEPRECATED_MEMORY_ALLOCATION_FUNCTIONS |
55 | | isc_mem_create("libxml2", &isc__xml_mctx); |
56 | | isc_mem_setdebugging(isc__xml_mctx, 0); |
57 | | isc_mem_setdestroycheck(isc__xml_mctx, false); |
58 | | |
59 | | RUNTIME_CHECK(xmlMemSetup(isc__xml_free, isc__xml_malloc, |
60 | | isc__xml_realloc, isc__xml_strdup) == 0); |
61 | | #endif /* !LIBXML_HAS_DEPRECATED_MEMORY_ALLOCATION_FUNCTIONS */ |
62 | | |
63 | | xmlInitParser(); |
64 | | #endif /* HAVE_LIBXML2 */ |
65 | 22 | } |
66 | | |
67 | | void |
68 | 0 | isc__xml_shutdown(void) { |
69 | | #ifdef HAVE_LIBXML2 |
70 | | xmlCleanupParser(); |
71 | | |
72 | | #ifndef LIBXML_HAS_DEPRECATED_MEMORY_ALLOCATION_FUNCTIONS |
73 | | isc_mem_detach(&isc__xml_mctx); |
74 | | #endif /* !LIBXML_HAS_DEPRECATED_MEMORY_ALLOCATION_FUNCTIONS */ |
75 | | #endif /* HAVE_LIBXML2 */ |
76 | 0 | } |
77 | | |
78 | | void |
79 | 0 | isc__xml_setdestroycheck(bool check ISC_ATTR_UNUSED) { |
80 | | #ifdef HAVE_LIBXML2 |
81 | | #ifndef LIBXML_HAS_DEPRECATED_MEMORY_ALLOCATION_FUNCTIONS |
82 | | isc_mem_setdestroycheck(isc__xml_mctx, check); |
83 | | #endif /* LIBXML_HAS_DEPRECATED_MEMORY_ALLOCATION_FUNCTIONS */ |
84 | | #endif /* HAVE_LIBXML2 */ |
85 | 0 | } |