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$ 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
;
52 struct option_chain_head
*h
;
55 log_error ("%s(%d): null pointer", file
, line
);
56 #if defined (POINTER_DEBUG)
63 log_error ("%s(%d): non-null pointer", file
, line
);
64 #if defined (POINTER_DEBUG)
67 *ptr
= (struct option_chain_head
*)0;
71 h
= dmalloc (sizeof *h
, file
, line
);
73 memset (h
, 0, sizeof *h
);
74 return option_chain_head_reference (ptr
, h
, file
, line
);
79 int option_chain_head_reference (ptr
, bp
, file
, line
)
80 struct option_chain_head
**ptr
;
81 struct option_chain_head
*bp
;
86 log_error ("%s(%d): null pointer", file
, line
);
87 #if defined (POINTER_DEBUG)
94 log_error ("%s(%d): non-null pointer", file
, line
);
95 #if defined (POINTER_DEBUG)
98 *ptr
= (struct option_chain_head
*)0;
103 rc_register (file
, line
, ptr
, bp
, bp
-> refcnt
, 0, RC_MISC
);
107 int option_chain_head_dereference (ptr
, file
, line
)
108 struct option_chain_head
**ptr
;
113 struct option_chain_head
*option_chain_head
;
117 log_error ("%s(%d): null pointer", file
, line
);
118 #if defined (POINTER_DEBUG)
125 option_chain_head
= *ptr
;
126 *ptr
= (struct option_chain_head
*)0;
127 --option_chain_head
-> refcnt
;
128 rc_register (file
, line
, ptr
, option_chain_head
,
129 option_chain_head
-> refcnt
, 1, RC_MISC
);
130 if (option_chain_head
-> refcnt
> 0)
133 if (option_chain_head
-> refcnt
< 0) {
134 log_error ("%s(%d): negative refcnt!", file
, line
);
135 #if defined (DEBUG_RC_HISTORY)
136 dump_rc_history (option_chain_head
);
138 #if defined (POINTER_DEBUG)
145 /* If there are any options on this head, free them. */
146 for (car
= option_chain_head
-> first
; car
; car
= cdr
) {
149 option_cache_dereference ((struct option_cache
**)
155 dfree (option_chain_head
, file
, line
);
159 int group_allocate (ptr
, file
, line
)
168 log_error ("%s(%d): null pointer", file
, line
);
169 #if defined (POINTER_DEBUG)
176 log_error ("%s(%d): non-null pointer", file
, line
);
177 #if defined (POINTER_DEBUG)
180 *ptr
= (struct group
*)0;
184 g
= dmalloc (sizeof *g
, file
, line
);
186 memset (g
, 0, sizeof *g
);
187 return group_reference (ptr
, g
, file
, line
);
192 int group_reference (ptr
, bp
, file
, line
)
199 log_error ("%s(%d): null pointer", file
, line
);
200 #if defined (POINTER_DEBUG)
207 log_error ("%s(%d): non-null pointer", file
, line
);
208 #if defined (POINTER_DEBUG)
211 *ptr
= (struct group
*)0;
216 rc_register (file
, line
, ptr
, bp
, bp
-> refcnt
, 0, RC_MISC
);
220 int group_dereference (ptr
, file
, line
)
229 log_error ("%s(%d): null pointer", file
, line
);
230 #if defined (POINTER_DEBUG)
238 *ptr
= (struct group
*)0;
240 rc_register (file
, line
, ptr
, group
, group
-> refcnt
, 1, RC_MISC
);
241 if (group
-> refcnt
> 0)
244 if (group
-> refcnt
< 0) {
245 log_error ("%s(%d): negative refcnt!", file
, line
);
246 #if defined (DEBUG_RC_HISTORY)
247 dump_rc_history (group
);
249 #if defined (POINTER_DEBUG)
257 group_object_dereference (&group
-> object
, file
, line
);
259 subnet_dereference (&group
-> subnet
, file
, line
);
260 if (group
-> shared_network
)
261 shared_network_dereference (&group
-> shared_network
,
263 if (group
-> statements
)
264 executable_statement_dereference (&group
-> statements
,
267 group_dereference (&group
-> next
, file
, line
);
268 dfree (group
, file
, line
);
272 struct dhcp_packet
*new_dhcp_packet (file
, line
)
276 struct dhcp_packet
*rval
;
277 rval
= (struct dhcp_packet
*)dmalloc (sizeof (struct dhcp_packet
),
282 struct protocol
*new_protocol (file
, line
)
286 struct protocol
*rval
= dmalloc (sizeof (struct protocol
), file
, line
);
290 struct domain_search_list
*new_domain_search_list (file
, line
)
294 struct domain_search_list
*rval
=
295 dmalloc (sizeof (struct domain_search_list
), file
, line
);
299 struct name_server
*new_name_server (file
, line
)
303 struct name_server
*rval
=
304 dmalloc (sizeof (struct name_server
), file
, line
);
308 void free_name_server (ptr
, file
, line
)
309 struct name_server
*ptr
;
313 dfree ((VOIDPTR
)ptr
, file
, line
);
316 struct option
*new_option (file
, line
)
320 struct option
*rval
=
321 dmalloc (sizeof (struct option
), file
, line
);
323 memset (rval
, 0, sizeof *rval
);
327 void free_option (ptr
, file
, line
)
332 /* XXX have to put all options on heap before this is possible. */
335 dfree ((VOIDPTR
)option
-> name
, file
, line
);
336 dfree ((VOIDPTR
)ptr
, file
, line
);
340 struct universe
*new_universe (file
, line
)
344 struct universe
*rval
=
345 dmalloc (sizeof (struct universe
), file
, line
);
349 void free_universe (ptr
, file
, line
)
350 struct universe
*ptr
;
354 dfree ((VOIDPTR
)ptr
, file
, line
);
357 void free_domain_search_list (ptr
, file
, line
)
358 struct domain_search_list
*ptr
;
362 dfree ((VOIDPTR
)ptr
, file
, line
);
365 void free_protocol (ptr
, file
, line
)
366 struct protocol
*ptr
;
370 dfree ((VOIDPTR
)ptr
, file
, line
);
373 void free_dhcp_packet (ptr
, file
, line
)
374 struct dhcp_packet
*ptr
;
378 dfree ((VOIDPTR
)ptr
, file
, line
);
381 struct client_lease
*new_client_lease (file
, line
)
385 return (struct client_lease
*)dmalloc (sizeof (struct client_lease
),
389 void free_client_lease (lease
, file
, line
)
390 struct client_lease
*lease
;
394 dfree (lease
, file
, line
);
399 pair
new_pair (file
, line
)
407 free_pairs
= foo
-> cdr
;
408 memset (foo
, 0, sizeof *foo
);
409 dmalloc_reuse (foo
, file
, line
, 0);
413 foo
= dmalloc (sizeof *foo
, file
, line
);
416 memset (foo
, 0, sizeof *foo
);
420 void free_pair (foo
, file
, line
)
425 foo
-> cdr
= free_pairs
;
427 dmalloc_reuse (free_pairs
, (char *)0, 0, 0);
430 #if defined (DEBUG_MEMORY_LEAKAGE) || \
431 defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
432 void relinquish_free_pairs ()
436 for (pf
= free_pairs
; pf
; pf
= pc
) {
440 free_pairs
= (pair
)0;
444 struct expression
*free_expressions
;
446 int expression_allocate (cptr
, file
, line
)
447 struct expression
**cptr
;
451 struct expression
*rval
;
453 if (free_expressions
) {
454 rval
= free_expressions
;
455 free_expressions
= rval
-> data
.not;
456 dmalloc_reuse (rval
, file
, line
, 1);
458 rval
= dmalloc (sizeof (struct expression
), file
, line
);
462 memset (rval
, 0, sizeof *rval
);
463 return expression_reference (cptr
, rval
, file
, line
);
466 int expression_reference (ptr
, src
, file
, line
)
467 struct expression
**ptr
;
468 struct expression
*src
;
473 log_error ("%s(%d): null pointer", file
, line
);
474 #if defined (POINTER_DEBUG)
481 log_error ("%s(%d): non-null pointer", file
, line
);
482 #if defined (POINTER_DEBUG)
485 *ptr
= (struct expression
*)0;
490 rc_register (file
, line
, ptr
, src
, src
-> refcnt
, 0, RC_MISC
);
494 void free_expression (expr
, file
, line
)
495 struct expression
*expr
;
499 expr
-> data
.not = free_expressions
;
500 free_expressions
= expr
;
501 dmalloc_reuse (free_expressions
, (char *)0, 0, 0);
504 #if defined (DEBUG_MEMORY_LEAKAGE) || \
505 defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
506 void relinquish_free_expressions ()
508 struct expression
*e
, *n
;
510 for (e
= free_expressions
; e
; e
= n
) {
514 free_expressions
= (struct expression
*)0;
518 struct binding_value
*free_binding_values
;
520 int binding_value_allocate (cptr
, file
, line
)
521 struct binding_value
**cptr
;
525 struct binding_value
*rval
;
527 if (free_binding_values
) {
528 rval
= free_binding_values
;
529 free_binding_values
= rval
-> value
.bv
;
530 dmalloc_reuse (rval
, file
, line
, 1);
532 rval
= dmalloc (sizeof (struct binding_value
), file
, line
);
536 memset (rval
, 0, sizeof *rval
);
537 return binding_value_reference (cptr
, rval
, file
, line
);
540 int binding_value_reference (ptr
, src
, file
, line
)
541 struct binding_value
**ptr
;
542 struct binding_value
*src
;
547 log_error ("%s(%d): null pointer", file
, line
);
548 #if defined (POINTER_DEBUG)
555 log_error ("%s(%d): non-null pointer", file
, line
);
556 #if defined (POINTER_DEBUG)
559 *ptr
= (struct binding_value
*)0;
564 rc_register (file
, line
, ptr
, src
, src
-> refcnt
, 0, RC_MISC
);
568 void free_binding_value (bv
, file
, line
)
569 struct binding_value
*bv
;
573 bv
-> value
.bv
= free_binding_values
;
574 free_binding_values
= bv
;
575 dmalloc_reuse (free_binding_values
, (char *)0, 0, 0);
578 #if defined (DEBUG_MEMORY_LEAKAGE) || \
579 defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
580 void relinquish_free_binding_values ()
582 struct binding_value
*b
, *n
;
584 for (b
= free_binding_values
; b
; b
= n
) {
588 free_binding_values
= (struct binding_value
*)0;
592 int fundef_allocate (cptr
, file
, line
)
593 struct fundef
**cptr
;
599 rval
= dmalloc (sizeof (struct fundef
), file
, line
);
602 memset (rval
, 0, sizeof *rval
);
603 return fundef_reference (cptr
, rval
, file
, line
);
606 int fundef_reference (ptr
, src
, file
, line
)
613 log_error ("%s(%d): null pointer", file
, line
);
614 #if defined (POINTER_DEBUG)
621 log_error ("%s(%d): non-null pointer", file
, line
);
622 #if defined (POINTER_DEBUG)
625 *ptr
= (struct fundef
*)0;
630 rc_register (file
, line
, ptr
, src
, src
-> refcnt
, 0, RC_MISC
);
634 struct option_cache
*free_option_caches
;
636 #if defined (DEBUG_MEMORY_LEAKAGE) || \
637 defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
638 void relinquish_free_option_caches ()
640 struct option_cache
*o
, *n
;
642 for (o
= free_option_caches
; o
; o
= n
) {
643 n
= (struct option_cache
*)(o
-> expression
);
646 free_option_caches
= (struct option_cache
*)0;
650 int option_cache_allocate (cptr
, file
, line
)
651 struct option_cache
**cptr
;
655 struct option_cache
*rval
;
657 if (free_option_caches
) {
658 rval
= free_option_caches
;
660 (struct option_cache
*)(rval
-> expression
);
661 dmalloc_reuse (rval
, file
, line
, 0);
663 rval
= dmalloc (sizeof (struct option_cache
), file
, line
);
667 memset (rval
, 0, sizeof *rval
);
668 return option_cache_reference (cptr
, rval
, file
, line
);
671 int option_cache_reference (ptr
, src
, file
, line
)
672 struct option_cache
**ptr
;
673 struct option_cache
*src
;
678 log_error ("%s(%d): null pointer", file
, line
);
679 #if defined (POINTER_DEBUG)
686 log_error ("%s(%d): non-null pointer", file
, line
);
687 #if defined (POINTER_DEBUG)
690 *ptr
= (struct option_cache
*)0;
695 rc_register (file
, line
, ptr
, src
, src
-> refcnt
, 0, RC_MISC
);
699 int buffer_allocate (ptr
, len
, file
, line
)
707 bp
= dmalloc (len
+ sizeof *bp
, file
, line
);
710 memset (bp
, 0, sizeof *bp
);
712 return buffer_reference (ptr
, bp
, file
, line
);
715 int buffer_reference (ptr
, bp
, file
, line
)
722 log_error ("%s(%d): null pointer", file
, line
);
723 #if defined (POINTER_DEBUG)
730 log_error ("%s(%d): non-null pointer", file
, line
);
731 #if defined (POINTER_DEBUG)
734 *ptr
= (struct buffer
*)0;
739 rc_register (file
, line
, ptr
, bp
, bp
-> refcnt
, 0, RC_MISC
);
743 int buffer_dereference (ptr
, file
, line
)
748 // struct buffer *bp;
751 log_error ("%s(%d): null pointer", file
, line
);
752 #if defined (POINTER_DEBUG)
760 log_error ("%s(%d): null pointer", file
, line
);
761 #if defined (POINTER_DEBUG)
769 rc_register (file
, line
, ptr
, *ptr
, (*ptr
) -> refcnt
, 1, RC_MISC
);
770 if (!(*ptr
) -> refcnt
) {
771 dfree ((*ptr
), file
, line
);
772 } else if ((*ptr
) -> refcnt
< 0) {
773 log_error ("%s(%d): negative refcnt!", file
, line
);
774 #if defined (DEBUG_RC_HISTORY)
775 dump_rc_history (*ptr
);
777 #if defined (POINTER_DEBUG)
783 *ptr
= (struct buffer
*)0;
787 int dns_host_entry_allocate (ptr
, hostname
, file
, line
)
788 struct dns_host_entry
**ptr
;
789 const char *hostname
;
793 struct dns_host_entry
*bp
;
795 bp
= dmalloc (strlen (hostname
) + sizeof *bp
, file
, line
);
798 memset (bp
, 0, sizeof *bp
);
800 strcpy (bp
-> hostname
, hostname
);
801 return dns_host_entry_reference (ptr
, bp
, file
, line
);
804 int dns_host_entry_reference (ptr
, bp
, file
, line
)
805 struct dns_host_entry
**ptr
;
806 struct dns_host_entry
*bp
;
811 log_error ("%s(%d): null pointer", file
, line
);
812 #if defined (POINTER_DEBUG)
819 log_error ("%s(%d): non-null pointer", file
, line
);
820 #if defined (POINTER_DEBUG)
823 *ptr
= (struct dns_host_entry
*)0;
828 rc_register (file
, line
, ptr
, bp
, bp
-> refcnt
, 0, RC_MISC
);
832 int dns_host_entry_dereference (ptr
, file
, line
)
833 struct dns_host_entry
**ptr
;
837 // struct dns_host_entry *bp;
840 log_error ("%s(%d): null pointer", file
, line
);
841 #if defined (POINTER_DEBUG)
849 rc_register (file
, line
, ptr
, *ptr
, (*ptr
) -> refcnt
, 1, RC_MISC
);
850 if (!(*ptr
) -> refcnt
)
851 dfree ((*ptr
), file
, line
);
852 if ((*ptr
) -> refcnt
< 0) {
853 log_error ("%s(%d): negative refcnt!", file
, line
);
854 #if defined (DEBUG_RC_HISTORY)
855 dump_rc_history (*ptr
);
857 #if defined (POINTER_DEBUG)
863 *ptr
= (struct dns_host_entry
*)0;
867 int option_state_allocate (ptr
, file
, line
)
868 struct option_state
**ptr
;
875 log_error ("%s(%d): null pointer", file
, line
);
876 #if defined (POINTER_DEBUG)
883 log_error ("%s(%d): non-null pointer", file
, line
);
884 #if defined (POINTER_DEBUG)
887 *ptr
= (struct option_state
*)0;
891 size
= sizeof **ptr
+ (universe_count
- 1) * sizeof (VOIDPTR
);
892 *ptr
= dmalloc (size
, file
, line
);
894 memset (*ptr
, 0, size
);
895 (*ptr
) -> universe_count
= universe_count
;
896 (*ptr
) -> refcnt
= 1;
897 rc_register (file
, line
,
898 ptr
, *ptr
, (*ptr
) -> refcnt
, 0, RC_MISC
);
904 int option_state_reference (ptr
, bp
, file
, line
)
905 struct option_state
**ptr
;
906 struct option_state
*bp
;
911 log_error ("%s(%d): null pointer", file
, line
);
912 #if defined (POINTER_DEBUG)
919 log_error ("%s(%d): non-null pointer", file
, line
);
920 #if defined (POINTER_DEBUG)
923 *ptr
= (struct option_state
*)0;
928 rc_register (file
, line
, ptr
, bp
, bp
-> refcnt
, 0, RC_MISC
);
932 int option_state_dereference (ptr
, file
, line
)
933 struct option_state
**ptr
;
938 struct option_state
*options
;
941 log_error ("%s(%d): null pointer", file
, line
);
942 #if defined (POINTER_DEBUG)
950 *ptr
= (struct option_state
*)0;
952 rc_register (file
, line
, ptr
, options
, options
-> refcnt
, 1, RC_MISC
);
953 if (options
-> refcnt
> 0)
956 if (options
-> refcnt
< 0) {
957 log_error ("%s(%d): negative refcnt!", file
, line
);
958 #if defined (DEBUG_RC_HISTORY)
959 dump_rc_history (options
);
961 #if defined (POINTER_DEBUG)
968 /* Loop through the per-universe state. */
969 for (i
= 0; i
< options
-> universe_count
; i
++)
970 if (options
-> universes
[i
] &&
971 universes
[i
] -> option_state_dereference
)
972 ((*(universes
[i
] -> option_state_dereference
))
973 (universes
[i
], options
, file
, line
));
974 dfree (options
, file
, line
);
978 int executable_statement_allocate (ptr
, file
, line
)
979 struct executable_statement
**ptr
;
983 struct executable_statement
*bp
;
985 bp
= dmalloc (sizeof *bp
, file
, line
);
988 memset (bp
, 0, sizeof *bp
);
989 return executable_statement_reference (ptr
, bp
, file
, line
);
992 int executable_statement_reference (ptr
, bp
, file
, line
)
993 struct executable_statement
**ptr
;
994 struct executable_statement
*bp
;
999 log_error ("%s(%d): null pointer", file
, line
);
1000 #if defined (POINTER_DEBUG)
1007 log_error ("%s(%d): non-null pointer", file
, line
);
1008 #if defined (POINTER_DEBUG)
1011 *ptr
= (struct executable_statement
*)0;
1016 rc_register (file
, line
, ptr
, bp
, bp
-> refcnt
, 0, RC_MISC
);
1020 static struct packet
*free_packets
;
1022 #if defined (DEBUG_MEMORY_LEAKAGE) || \
1023 defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
1024 void relinquish_free_packets ()
1026 struct packet
*p
, *n
;
1027 for (p
= free_packets
; p
; p
= n
) {
1028 n
= (struct packet
*)(p
-> raw
);
1031 free_packets
= (struct packet
*)0;
1035 int packet_allocate (ptr
, file
, line
)
1036 struct packet
**ptr
;
1044 log_error ("%s(%d): null pointer", file
, line
);
1045 #if defined (POINTER_DEBUG)
1052 log_error ("%s(%d): non-null pointer", file
, line
);
1053 #if defined (POINTER_DEBUG)
1056 *ptr
= (struct packet
*)0;
1062 free_packets
= (struct packet
*)(p
-> raw
);
1063 dmalloc_reuse (p
, file
, line
, 1);
1065 p
= dmalloc (sizeof *p
, file
, line
);
1068 memset (p
, 0, sizeof *p
);
1069 return packet_reference (ptr
, p
, file
, line
);
1074 int packet_reference (ptr
, bp
, file
, line
)
1075 struct packet
**ptr
;
1081 log_error ("%s(%d): null pointer", file
, line
);
1082 #if defined (POINTER_DEBUG)
1089 log_error ("%s(%d): non-null pointer", file
, line
);
1090 #if defined (POINTER_DEBUG)
1093 *ptr
= (struct packet
*)0;
1098 rc_register (file
, line
, ptr
, bp
, bp
-> refcnt
, 0, RC_MISC
);
1102 int packet_dereference (ptr
, file
, line
)
1103 struct packet
**ptr
;
1108 struct packet
*packet
;
1110 if (!ptr
|| !*ptr
) {
1111 log_error ("%s(%d): null pointer", file
, line
);
1112 #if defined (POINTER_DEBUG)
1120 *ptr
= (struct packet
*)0;
1122 rc_register (file
, line
, ptr
, packet
, packet
-> refcnt
, 1, RC_MISC
);
1123 if (packet
-> refcnt
> 0)
1126 if (packet
-> refcnt
< 0) {
1127 log_error ("%s(%d): negative refcnt!", file
, line
);
1128 #if defined (DEBUG_RC_HISTORY)
1129 dump_rc_history (packet
);
1131 #if defined (POINTER_DEBUG)
1138 if (packet
-> options
)
1139 option_state_dereference (&packet
-> options
, file
, line
);
1140 if (packet
-> interface
)
1141 interface_dereference (&packet
-> interface
, MDL
);
1142 if (packet
-> shared_network
)
1143 shared_network_dereference (&packet
-> shared_network
, MDL
);
1144 for (i
= 0; i
< packet
-> class_count
&& i
< PACKET_MAX_CLASSES
; i
++) {
1145 if (packet
-> classes
[i
])
1146 omapi_object_dereference ((omapi_object_t
**)
1147 &packet
-> classes
[i
], MDL
);
1149 packet
-> raw
= (struct dhcp_packet
*)free_packets
;
1150 free_packets
= packet
;
1151 dmalloc_reuse (free_packets
, (char *)0, 0, 0);
1155 int dns_zone_allocate (ptr
, file
, line
)
1156 struct dns_zone
**ptr
;
1164 log_error ("%s(%d): null pointer", file
, line
);
1165 #if defined (POINTER_DEBUG)
1172 log_error ("%s(%d): non-null pointer", file
, line
);
1173 #if defined (POINTER_DEBUG)
1176 *ptr
= (struct dns_zone
*)0;
1180 d
= dmalloc (sizeof *d
, file
, line
);
1182 memset (d
, 0, sizeof *d
);
1183 return dns_zone_reference (ptr
, d
, file
, line
);
1188 int dns_zone_reference (ptr
, bp
, file
, line
)
1189 struct dns_zone
**ptr
;
1190 struct dns_zone
*bp
;
1195 log_error ("%s(%d): null pointer", file
, line
);
1196 #if defined (POINTER_DEBUG)
1203 log_error ("%s(%d): non-null pointer", file
, line
);
1204 #if defined (POINTER_DEBUG)
1207 *ptr
= (struct dns_zone
*)0;
1212 rc_register (file
, line
, ptr
, bp
, bp
-> refcnt
, 0, RC_MISC
);
1216 int binding_scope_allocate (ptr
, file
, line
)
1217 struct binding_scope
**ptr
;
1221 struct binding_scope
*bp
;
1224 log_error ("%s(%d): null pointer", file
, line
);
1225 #if defined (POINTER_DEBUG)
1233 log_error ("%s(%d): non-null pointer", file
, line
);
1234 #if defined (POINTER_DEBUG)
1241 bp
= dmalloc (sizeof *bp
, file
, line
);
1244 memset (bp
, 0, sizeof *bp
);
1245 binding_scope_reference (ptr
, bp
, file
, line
);
1249 int binding_scope_reference (ptr
, bp
, file
, line
)
1250 struct binding_scope
**ptr
;
1251 struct binding_scope
*bp
;
1256 log_error ("%s(%d): null pointer", file
, line
);
1257 #if defined (POINTER_DEBUG)
1264 log_error ("%s(%d): non-null pointer", file
, line
);
1265 #if defined (POINTER_DEBUG)
1268 *ptr
= (struct binding_scope
*)0;
1273 rc_register (file
, line
, ptr
, bp
, bp
-> refcnt
, 0, RC_MISC
);
1277 /* Make a copy of the data in data_string, upping the buffer reference
1278 count if there's a buffer. */
1280 void data_string_copy (dest
, src
, file
, line
)
1281 struct data_string
*dest
;
1282 struct data_string
*src
;
1287 buffer_reference (&dest
-> buffer
, src
-> buffer
, file
, line
);
1288 dest
-> data
= src
-> data
;
1289 dest
-> terminated
= src
-> terminated
;
1290 dest
-> len
= src
-> len
;
1293 /* Release the reference count to a data string's buffer (if any) and
1294 zero out the other information, yielding the null data string. */
1296 void data_string_forget (data
, file
, line
)
1297 struct data_string
*data
;
1302 buffer_dereference (&data
-> buffer
, file
, line
);
1303 memset (data
, 0, sizeof *data
);
1306 /* Make a copy of the data in data_string, upping the buffer reference
1307 count if there's a buffer. */
1309 void data_string_truncate (dp
, len
)
1310 struct data_string
*dp
;
1313 if (len
< dp
-> len
) {
1314 dp
-> terminated
= 0;