3 Memory allocation... */
6 * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
7 * Copyright (c) 1996-2003 by Internet Software Consortium
9 * Permission to use, copy, modify, and distribute this software for any
10 * purpose with or without fee is hereby granted, provided that the above
11 * copyright notice and this permission notice appear in all copies.
13 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
14 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
16 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
19 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 * Internet Systems Consortium, Inc.
23 * Redwood City, CA 94063
27 * This software has been written for Internet Systems Consortium
28 * by Ted Lemon in cooperation with Vixie Enterprises and Nominum, Inc.
29 * To learn more about Internet Systems Consortium, see
30 * ``http://www.isc.org/''. To learn more about Vixie Enterprises,
31 * see ``http://www.vix.com''. To learn more about Nominum, Inc., see
32 * ``http://www.nominum.com''.
36 static char copyright
[] =
37 "$Id: alloc.c,v 1.5 2005/08/11 17:13:21 drochner Exp $ Copyright (c) 2004 Internet Systems Consortium. All rights reserved.\n";
41 #include <omapip/omapip_p.h>
43 struct dhcp_packet
*dhcp_free_list
;
44 struct packet
*packet_free_list
;
46 int option_chain_head_allocate (ptr
, file
, line
)
47 struct option_chain_head
**ptr
;
51 struct option_chain_head
*h
;
54 log_error ("%s(%d): null pointer", file
, line
);
55 #if defined (POINTER_DEBUG)
62 log_error ("%s(%d): non-null pointer", file
, line
);
63 #if defined (POINTER_DEBUG)
66 *ptr
= (struct option_chain_head
*)0;
70 h
= dmalloc (sizeof *h
, file
, line
);
72 memset (h
, 0, sizeof *h
);
73 return option_chain_head_reference (ptr
, h
, file
, line
);
78 int option_chain_head_reference (ptr
, bp
, file
, line
)
79 struct option_chain_head
**ptr
;
80 struct option_chain_head
*bp
;
85 log_error ("%s(%d): null pointer", file
, line
);
86 #if defined (POINTER_DEBUG)
93 log_error ("%s(%d): non-null pointer", file
, line
);
94 #if defined (POINTER_DEBUG)
97 *ptr
= (struct option_chain_head
*)0;
102 rc_register (file
, line
, ptr
, bp
, bp
-> refcnt
, 0, RC_MISC
);
106 int option_chain_head_dereference (ptr
, file
, line
)
107 struct option_chain_head
**ptr
;
111 struct option_chain_head
*option_chain_head
;
115 log_error ("%s(%d): null pointer", file
, line
);
116 #if defined (POINTER_DEBUG)
123 option_chain_head
= *ptr
;
124 *ptr
= (struct option_chain_head
*)0;
125 --option_chain_head
-> refcnt
;
126 rc_register (file
, line
, ptr
, option_chain_head
,
127 option_chain_head
-> refcnt
, 1, RC_MISC
);
128 if (option_chain_head
-> refcnt
> 0)
131 if (option_chain_head
-> refcnt
< 0) {
132 log_error ("%s(%d): negative refcnt!", file
, line
);
133 #if defined (DEBUG_RC_HISTORY)
134 dump_rc_history (option_chain_head
);
136 #if defined (POINTER_DEBUG)
143 /* If there are any options on this head, free them. */
144 for (car
= option_chain_head
-> first
; car
; car
= cdr
) {
147 option_cache_dereference ((struct option_cache
**)
153 dfree (option_chain_head
, file
, line
);
157 int group_allocate (ptr
, file
, line
)
165 log_error ("%s(%d): null pointer", file
, line
);
166 #if defined (POINTER_DEBUG)
173 log_error ("%s(%d): non-null pointer", file
, line
);
174 #if defined (POINTER_DEBUG)
177 *ptr
= (struct group
*)0;
181 g
= dmalloc (sizeof *g
, file
, line
);
183 memset (g
, 0, sizeof *g
);
184 return group_reference (ptr
, g
, file
, line
);
189 int group_reference (ptr
, bp
, file
, line
)
196 log_error ("%s(%d): null pointer", file
, line
);
197 #if defined (POINTER_DEBUG)
204 log_error ("%s(%d): non-null pointer", file
, line
);
205 #if defined (POINTER_DEBUG)
208 *ptr
= (struct group
*)0;
213 rc_register (file
, line
, ptr
, bp
, bp
-> refcnt
, 0, RC_MISC
);
217 int group_dereference (ptr
, file
, line
)
225 log_error ("%s(%d): null pointer", file
, line
);
226 #if defined (POINTER_DEBUG)
234 *ptr
= (struct group
*)0;
236 rc_register (file
, line
, ptr
, group
, group
-> refcnt
, 1, RC_MISC
);
237 if (group
-> refcnt
> 0)
240 if (group
-> refcnt
< 0) {
241 log_error ("%s(%d): negative refcnt!", file
, line
);
242 #if defined (DEBUG_RC_HISTORY)
243 dump_rc_history (group
);
245 #if defined (POINTER_DEBUG)
253 group_object_dereference (&group
-> object
, file
, line
);
255 subnet_dereference (&group
-> subnet
, file
, line
);
256 if (group
-> shared_network
)
257 shared_network_dereference (&group
-> shared_network
,
259 if (group
-> statements
)
260 executable_statement_dereference (&group
-> statements
,
263 group_dereference (&group
-> next
, file
, line
);
264 dfree (group
, file
, line
);
268 struct dhcp_packet
*new_dhcp_packet (file
, line
)
272 struct dhcp_packet
*rval
;
273 rval
= (struct dhcp_packet
*)dmalloc (sizeof (struct dhcp_packet
),
278 struct protocol
*new_protocol (file
, line
)
282 struct protocol
*rval
= dmalloc (sizeof (struct protocol
), file
, line
);
286 struct domain_search_list
*new_domain_search_list (file
, line
)
290 struct domain_search_list
*rval
=
291 dmalloc (sizeof (struct domain_search_list
), file
, line
);
295 struct name_server
*new_name_server (file
, line
)
299 struct name_server
*rval
=
300 dmalloc (sizeof (struct name_server
), file
, line
);
304 void free_name_server (ptr
, file
, line
)
305 struct name_server
*ptr
;
309 dfree ((VOIDPTR
)ptr
, file
, line
);
312 struct option
*new_option (file
, line
)
316 struct option
*rval
=
317 dmalloc (sizeof (struct option
), file
, line
);
319 memset (rval
, 0, sizeof *rval
);
323 void free_option (ptr
, file
, line
)
328 /* XXX have to put all options on heap before this is possible. */
331 dfree ((VOIDPTR
)option
-> name
, file
, line
);
332 dfree ((VOIDPTR
)ptr
, file
, line
);
336 struct universe
*new_universe (file
, line
)
340 struct universe
*rval
=
341 dmalloc (sizeof (struct universe
), file
, line
);
345 void free_universe (ptr
, file
, line
)
346 struct universe
*ptr
;
350 dfree ((VOIDPTR
)ptr
, file
, line
);
353 void free_domain_search_list (ptr
, file
, line
)
354 struct domain_search_list
*ptr
;
358 dfree ((VOIDPTR
)ptr
, file
, line
);
361 void free_protocol (ptr
, file
, line
)
362 struct protocol
*ptr
;
366 dfree ((VOIDPTR
)ptr
, file
, line
);
369 void free_dhcp_packet (ptr
, file
, line
)
370 struct dhcp_packet
*ptr
;
374 dfree ((VOIDPTR
)ptr
, file
, line
);
377 struct client_lease
*new_client_lease (file
, line
)
381 return (struct client_lease
*)dmalloc (sizeof (struct client_lease
),
385 void free_client_lease (lease
, file
, line
)
386 struct client_lease
*lease
;
390 dfree (lease
, file
, line
);
395 pair
new_pair (file
, line
)
403 free_pairs
= foo
-> cdr
;
404 memset (foo
, 0, sizeof *foo
);
405 dmalloc_reuse (foo
, file
, line
, 0);
409 foo
= dmalloc (sizeof *foo
, file
, line
);
412 memset (foo
, 0, sizeof *foo
);
416 void free_pair (foo
, file
, line
)
421 foo
-> cdr
= free_pairs
;
423 dmalloc_reuse (free_pairs
, (char *)0, 0, 0);
426 #if defined (DEBUG_MEMORY_LEAKAGE) || \
427 defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
428 void relinquish_free_pairs ()
432 for (pf
= free_pairs
; pf
; pf
= pc
) {
436 free_pairs
= (pair
)0;
440 struct expression
*free_expressions
;
442 int expression_allocate (cptr
, file
, line
)
443 struct expression
**cptr
;
447 struct expression
*rval
;
449 if (free_expressions
) {
450 rval
= free_expressions
;
451 free_expressions
= rval
-> data
.not;
452 dmalloc_reuse (rval
, file
, line
, 1);
454 rval
= dmalloc (sizeof (struct expression
), file
, line
);
458 memset (rval
, 0, sizeof *rval
);
459 return expression_reference (cptr
, rval
, file
, line
);
462 int expression_reference (ptr
, src
, file
, line
)
463 struct expression
**ptr
;
464 struct expression
*src
;
469 log_error ("%s(%d): null pointer", file
, line
);
470 #if defined (POINTER_DEBUG)
477 log_error ("%s(%d): non-null pointer", file
, line
);
478 #if defined (POINTER_DEBUG)
481 *ptr
= (struct expression
*)0;
486 rc_register (file
, line
, ptr
, src
, src
-> refcnt
, 0, RC_MISC
);
490 void free_expression (expr
, file
, line
)
491 struct expression
*expr
;
495 expr
-> data
.not = free_expressions
;
496 free_expressions
= expr
;
497 dmalloc_reuse (free_expressions
, (char *)0, 0, 0);
500 #if defined (DEBUG_MEMORY_LEAKAGE) || \
501 defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
502 void relinquish_free_expressions ()
504 struct expression
*e
, *n
;
506 for (e
= free_expressions
; e
; e
= n
) {
510 free_expressions
= (struct expression
*)0;
514 struct binding_value
*free_binding_values
;
516 int binding_value_allocate (cptr
, file
, line
)
517 struct binding_value
**cptr
;
521 struct binding_value
*rval
;
523 if (free_binding_values
) {
524 rval
= free_binding_values
;
525 free_binding_values
= rval
-> value
.bv
;
526 dmalloc_reuse (rval
, file
, line
, 1);
528 rval
= dmalloc (sizeof (struct binding_value
), file
, line
);
532 memset (rval
, 0, sizeof *rval
);
533 return binding_value_reference (cptr
, rval
, file
, line
);
536 int binding_value_reference (ptr
, src
, file
, line
)
537 struct binding_value
**ptr
;
538 struct binding_value
*src
;
543 log_error ("%s(%d): null pointer", file
, line
);
544 #if defined (POINTER_DEBUG)
551 log_error ("%s(%d): non-null pointer", file
, line
);
552 #if defined (POINTER_DEBUG)
555 *ptr
= (struct binding_value
*)0;
560 rc_register (file
, line
, ptr
, src
, src
-> refcnt
, 0, RC_MISC
);
564 void free_binding_value (bv
, file
, line
)
565 struct binding_value
*bv
;
569 bv
-> value
.bv
= free_binding_values
;
570 free_binding_values
= bv
;
571 dmalloc_reuse (free_binding_values
, (char *)0, 0, 0);
574 #if defined (DEBUG_MEMORY_LEAKAGE) || \
575 defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
576 void relinquish_free_binding_values ()
578 struct binding_value
*b
, *n
;
580 for (b
= free_binding_values
; b
; b
= n
) {
584 free_binding_values
= (struct binding_value
*)0;
588 int fundef_allocate (cptr
, file
, line
)
589 struct fundef
**cptr
;
595 rval
= dmalloc (sizeof (struct fundef
), file
, line
);
598 memset (rval
, 0, sizeof *rval
);
599 return fundef_reference (cptr
, rval
, file
, line
);
602 int fundef_reference (ptr
, src
, file
, line
)
609 log_error ("%s(%d): null pointer", file
, line
);
610 #if defined (POINTER_DEBUG)
617 log_error ("%s(%d): non-null pointer", file
, line
);
618 #if defined (POINTER_DEBUG)
621 *ptr
= (struct fundef
*)0;
626 rc_register (file
, line
, ptr
, src
, src
-> refcnt
, 0, RC_MISC
);
630 struct option_cache
*free_option_caches
;
632 #if defined (DEBUG_MEMORY_LEAKAGE) || \
633 defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
634 void relinquish_free_option_caches ()
636 struct option_cache
*o
, *n
;
638 for (o
= free_option_caches
; o
; o
= n
) {
639 n
= (struct option_cache
*)(o
-> expression
);
642 free_option_caches
= (struct option_cache
*)0;
646 int option_cache_allocate (cptr
, file
, line
)
647 struct option_cache
**cptr
;
651 struct option_cache
*rval
;
653 if (free_option_caches
) {
654 rval
= free_option_caches
;
656 (struct option_cache
*)(rval
-> expression
);
657 dmalloc_reuse (rval
, file
, line
, 0);
659 rval
= dmalloc (sizeof (struct option_cache
), file
, line
);
663 memset (rval
, 0, sizeof *rval
);
664 return option_cache_reference (cptr
, rval
, file
, line
);
667 int option_cache_reference (ptr
, src
, file
, line
)
668 struct option_cache
**ptr
;
669 struct option_cache
*src
;
674 log_error ("%s(%d): null pointer", file
, line
);
675 #if defined (POINTER_DEBUG)
682 log_error ("%s(%d): non-null pointer", file
, line
);
683 #if defined (POINTER_DEBUG)
686 *ptr
= (struct option_cache
*)0;
691 rc_register (file
, line
, ptr
, src
, src
-> refcnt
, 0, RC_MISC
);
695 int buffer_allocate (ptr
, len
, file
, line
)
703 bp
= dmalloc (len
+ sizeof *bp
, file
, line
);
706 memset (bp
, 0, sizeof *bp
);
708 return buffer_reference (ptr
, bp
, file
, line
);
711 int buffer_reference (ptr
, bp
, file
, line
)
718 log_error ("%s(%d): null pointer", file
, line
);
719 #if defined (POINTER_DEBUG)
726 log_error ("%s(%d): non-null pointer", file
, line
);
727 #if defined (POINTER_DEBUG)
730 *ptr
= (struct buffer
*)0;
735 rc_register (file
, line
, ptr
, bp
, bp
-> refcnt
, 0, RC_MISC
);
739 int buffer_dereference (ptr
, file
, line
)
746 log_error ("%s(%d): null pointer", file
, line
);
747 #if defined (POINTER_DEBUG)
755 log_error ("%s(%d): null pointer", file
, line
);
756 #if defined (POINTER_DEBUG)
764 rc_register (file
, line
, ptr
, *ptr
, (*ptr
) -> refcnt
, 1, RC_MISC
);
765 if (!(*ptr
) -> refcnt
) {
766 dfree ((*ptr
), file
, line
);
767 } else if ((*ptr
) -> refcnt
< 0) {
768 log_error ("%s(%d): negative refcnt!", file
, line
);
769 #if defined (DEBUG_RC_HISTORY)
770 dump_rc_history (*ptr
);
772 #if defined (POINTER_DEBUG)
778 *ptr
= (struct buffer
*)0;
782 int dns_host_entry_allocate (ptr
, hostname
, file
, line
)
783 struct dns_host_entry
**ptr
;
784 const char *hostname
;
788 struct dns_host_entry
*bp
;
790 bp
= dmalloc (strlen (hostname
) + sizeof *bp
, file
, line
);
793 memset (bp
, 0, sizeof *bp
);
795 strcpy (bp
-> hostname
, hostname
);
796 return dns_host_entry_reference (ptr
, bp
, file
, line
);
799 int dns_host_entry_reference (ptr
, bp
, file
, line
)
800 struct dns_host_entry
**ptr
;
801 struct dns_host_entry
*bp
;
806 log_error ("%s(%d): null pointer", file
, line
);
807 #if defined (POINTER_DEBUG)
814 log_error ("%s(%d): non-null pointer", file
, line
);
815 #if defined (POINTER_DEBUG)
818 *ptr
= (struct dns_host_entry
*)0;
823 rc_register (file
, line
, ptr
, bp
, bp
-> refcnt
, 0, RC_MISC
);
827 int dns_host_entry_dereference (ptr
, file
, line
)
828 struct dns_host_entry
**ptr
;
834 log_error ("%s(%d): null pointer", file
, line
);
835 #if defined (POINTER_DEBUG)
843 rc_register (file
, line
, ptr
, *ptr
, (*ptr
) -> refcnt
, 1, RC_MISC
);
844 if (!(*ptr
) -> refcnt
)
845 dfree ((*ptr
), file
, line
);
846 if ((*ptr
) -> refcnt
< 0) {
847 log_error ("%s(%d): negative refcnt!", file
, line
);
848 #if defined (DEBUG_RC_HISTORY)
849 dump_rc_history (*ptr
);
851 #if defined (POINTER_DEBUG)
857 *ptr
= (struct dns_host_entry
*)0;
861 int option_state_allocate (ptr
, file
, line
)
862 struct option_state
**ptr
;
869 log_error ("%s(%d): null pointer", file
, line
);
870 #if defined (POINTER_DEBUG)
877 log_error ("%s(%d): non-null pointer", file
, line
);
878 #if defined (POINTER_DEBUG)
881 *ptr
= (struct option_state
*)0;
885 size
= sizeof **ptr
+ (universe_count
- 1) * sizeof (VOIDPTR
);
886 *ptr
= dmalloc (size
, file
, line
);
888 memset (*ptr
, 0, size
);
889 (*ptr
) -> universe_count
= universe_count
;
890 (*ptr
) -> refcnt
= 1;
891 rc_register (file
, line
,
892 ptr
, *ptr
, (*ptr
) -> refcnt
, 0, RC_MISC
);
898 int option_state_reference (ptr
, bp
, file
, line
)
899 struct option_state
**ptr
;
900 struct option_state
*bp
;
905 log_error ("%s(%d): null pointer", file
, line
);
906 #if defined (POINTER_DEBUG)
913 log_error ("%s(%d): non-null pointer", file
, line
);
914 #if defined (POINTER_DEBUG)
917 *ptr
= (struct option_state
*)0;
922 rc_register (file
, line
, ptr
, bp
, bp
-> refcnt
, 0, RC_MISC
);
926 int option_state_dereference (ptr
, file
, line
)
927 struct option_state
**ptr
;
932 struct option_state
*options
;
935 log_error ("%s(%d): null pointer", file
, line
);
936 #if defined (POINTER_DEBUG)
944 *ptr
= (struct option_state
*)0;
946 rc_register (file
, line
, ptr
, options
, options
-> refcnt
, 1, RC_MISC
);
947 if (options
-> refcnt
> 0)
950 if (options
-> refcnt
< 0) {
951 log_error ("%s(%d): negative refcnt!", file
, line
);
952 #if defined (DEBUG_RC_HISTORY)
953 dump_rc_history (options
);
955 #if defined (POINTER_DEBUG)
962 /* Loop through the per-universe state. */
963 for (i
= 0; i
< options
-> universe_count
; i
++)
964 if (options
-> universes
[i
] &&
965 universes
[i
] -> option_state_dereference
)
966 ((*(universes
[i
] -> option_state_dereference
))
967 (universes
[i
], options
, file
, line
));
968 dfree (options
, file
, line
);
972 int executable_statement_allocate (ptr
, file
, line
)
973 struct executable_statement
**ptr
;
977 struct executable_statement
*bp
;
979 bp
= dmalloc (sizeof *bp
, file
, line
);
982 memset (bp
, 0, sizeof *bp
);
983 return executable_statement_reference (ptr
, bp
, file
, line
);
986 int executable_statement_reference (ptr
, bp
, file
, line
)
987 struct executable_statement
**ptr
;
988 struct executable_statement
*bp
;
993 log_error ("%s(%d): null pointer", file
, line
);
994 #if defined (POINTER_DEBUG)
1001 log_error ("%s(%d): non-null pointer", file
, line
);
1002 #if defined (POINTER_DEBUG)
1005 *ptr
= (struct executable_statement
*)0;
1010 rc_register (file
, line
, ptr
, bp
, bp
-> refcnt
, 0, RC_MISC
);
1014 static struct packet
*free_packets
;
1016 #if defined (DEBUG_MEMORY_LEAKAGE) || \
1017 defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
1018 void relinquish_free_packets ()
1020 struct packet
*p
, *n
;
1021 for (p
= free_packets
; p
; p
= n
) {
1022 n
= (struct packet
*)(p
-> raw
);
1025 free_packets
= (struct packet
*)0;
1029 int packet_allocate (ptr
, file
, line
)
1030 struct packet
**ptr
;
1037 log_error ("%s(%d): null pointer", file
, line
);
1038 #if defined (POINTER_DEBUG)
1045 log_error ("%s(%d): non-null pointer", file
, line
);
1046 #if defined (POINTER_DEBUG)
1049 *ptr
= (struct packet
*)0;
1055 free_packets
= (struct packet
*)(p
-> raw
);
1056 dmalloc_reuse (p
, file
, line
, 1);
1058 p
= dmalloc (sizeof *p
, file
, line
);
1061 memset (p
, 0, sizeof *p
);
1062 return packet_reference (ptr
, p
, file
, line
);
1067 int packet_reference (ptr
, bp
, file
, line
)
1068 struct packet
**ptr
;
1074 log_error ("%s(%d): null pointer", file
, line
);
1075 #if defined (POINTER_DEBUG)
1082 log_error ("%s(%d): non-null pointer", file
, line
);
1083 #if defined (POINTER_DEBUG)
1086 *ptr
= (struct packet
*)0;
1091 rc_register (file
, line
, ptr
, bp
, bp
-> refcnt
, 0, RC_MISC
);
1095 int packet_dereference (ptr
, file
, line
)
1096 struct packet
**ptr
;
1101 struct packet
*packet
;
1103 if (!ptr
|| !*ptr
) {
1104 log_error ("%s(%d): null pointer", file
, line
);
1105 #if defined (POINTER_DEBUG)
1113 *ptr
= (struct packet
*)0;
1115 rc_register (file
, line
, ptr
, packet
, packet
-> refcnt
, 1, RC_MISC
);
1116 if (packet
-> refcnt
> 0)
1119 if (packet
-> refcnt
< 0) {
1120 log_error ("%s(%d): negative refcnt!", file
, line
);
1121 #if defined (DEBUG_RC_HISTORY)
1122 dump_rc_history (packet
);
1124 #if defined (POINTER_DEBUG)
1131 if (packet
-> options
)
1132 option_state_dereference (&packet
-> options
, file
, line
);
1133 if (packet
-> interface
)
1134 interface_dereference (&packet
-> interface
, MDL
);
1135 if (packet
-> shared_network
)
1136 shared_network_dereference (&packet
-> shared_network
, MDL
);
1137 for (i
= 0; i
< packet
-> class_count
&& i
< PACKET_MAX_CLASSES
; i
++) {
1138 if (packet
-> classes
[i
])
1139 omapi_object_dereference ((omapi_object_t
**)
1140 &packet
-> classes
[i
], MDL
);
1142 packet
-> raw
= (struct dhcp_packet
*)free_packets
;
1143 free_packets
= packet
;
1144 dmalloc_reuse (free_packets
, (char *)0, 0, 0);
1148 int dns_zone_allocate (ptr
, file
, line
)
1149 struct dns_zone
**ptr
;
1156 log_error ("%s(%d): null pointer", file
, line
);
1157 #if defined (POINTER_DEBUG)
1164 log_error ("%s(%d): non-null pointer", file
, line
);
1165 #if defined (POINTER_DEBUG)
1168 *ptr
= (struct dns_zone
*)0;
1172 d
= dmalloc (sizeof *d
, file
, line
);
1174 memset (d
, 0, sizeof *d
);
1175 return dns_zone_reference (ptr
, d
, file
, line
);
1180 int dns_zone_reference (ptr
, bp
, file
, line
)
1181 struct dns_zone
**ptr
;
1182 struct dns_zone
*bp
;
1187 log_error ("%s(%d): null pointer", file
, line
);
1188 #if defined (POINTER_DEBUG)
1195 log_error ("%s(%d): non-null pointer", file
, line
);
1196 #if defined (POINTER_DEBUG)
1199 *ptr
= (struct dns_zone
*)0;
1204 rc_register (file
, line
, ptr
, bp
, bp
-> refcnt
, 0, RC_MISC
);
1208 int binding_scope_allocate (ptr
, file
, line
)
1209 struct binding_scope
**ptr
;
1213 struct binding_scope
*bp
;
1216 log_error ("%s(%d): null pointer", file
, line
);
1217 #if defined (POINTER_DEBUG)
1225 log_error ("%s(%d): non-null pointer", file
, line
);
1226 #if defined (POINTER_DEBUG)
1233 bp
= dmalloc (sizeof *bp
, file
, line
);
1236 memset (bp
, 0, sizeof *bp
);
1237 binding_scope_reference (ptr
, bp
, file
, line
);
1241 int binding_scope_reference (ptr
, bp
, file
, line
)
1242 struct binding_scope
**ptr
;
1243 struct binding_scope
*bp
;
1248 log_error ("%s(%d): null pointer", file
, line
);
1249 #if defined (POINTER_DEBUG)
1256 log_error ("%s(%d): non-null pointer", file
, line
);
1257 #if defined (POINTER_DEBUG)
1260 *ptr
= (struct binding_scope
*)0;
1265 rc_register (file
, line
, ptr
, bp
, bp
-> refcnt
, 0, RC_MISC
);
1269 /* Make a copy of the data in data_string, upping the buffer reference
1270 count if there's a buffer. */
1272 void data_string_copy (dest
, src
, file
, line
)
1273 struct data_string
*dest
;
1274 struct data_string
*src
;
1279 buffer_reference (&dest
-> buffer
, src
-> buffer
, file
, line
);
1280 dest
-> data
= src
-> data
;
1281 dest
-> terminated
= src
-> terminated
;
1282 dest
-> len
= src
-> len
;
1285 /* Release the reference count to a data string's buffer (if any) and
1286 zero out the other information, yielding the null data string. */
1288 void data_string_forget (data
, file
, line
)
1289 struct data_string
*data
;
1294 buffer_dereference (&data
-> buffer
, file
, line
);
1295 memset (data
, 0, sizeof *data
);
1298 /* Make a copy of the data in data_string, upping the buffer reference
1299 count if there's a buffer. */
1301 void data_string_truncate (dp
, len
)
1302 struct data_string
*dp
;
1305 if (len
< dp
-> len
) {
1306 dp
-> terminated
= 0;