]>
git.ipfire.org Git - thirdparty/dhcp.git/blob - common/alloc.c
3 Memory allocation... */
6 * Copyright (c) 1996-2000 Internet Software Consortium.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of The Internet Software Consortium nor the names
19 * of its contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE INTERNET SOFTWARE CONSORTIUM AND
23 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
24 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 * DISCLAIMED. IN NO EVENT SHALL THE INTERNET SOFTWARE CONSORTIUM OR
27 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
30 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
33 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * This software has been written for the Internet Software Consortium
37 * by Ted Lemon in cooperation with Vixie Enterprises and Nominum, Inc.
38 * To learn more about the Internet Software Consortium, see
39 * ``http://www.isc.org/''. To learn more about Vixie Enterprises,
40 * see ``http://www.vix.com''. To learn more about Nominum, Inc., see
41 * ``http://www.nominum.com''.
45 static char copyright
[] =
46 "$Id: alloc.c,v 1.47 2000/05/16 23:02:08 mellon Exp $ Copyright (c) 1996-2000 The Internet Software Consortium. All rights reserved.\n";
50 #include <omapip/omapip_p.h>
52 struct dhcp_packet
*dhcp_free_list
;
53 struct packet
*packet_free_list
;
55 OMAPI_OBJECT_ALLOC (subnet
, struct subnet
, dhcp_type_subnet
)
56 OMAPI_OBJECT_ALLOC (shared_network
, struct shared_network
,
57 dhcp_type_shared_network
)
58 OMAPI_OBJECT_ALLOC (group_object
, struct group_object
, dhcp_type_group
)
60 int group_allocate (ptr
, file
, line
)
68 log_error ("%s(%d): null pointer", file
, line
);
69 #if defined (POINTER_DEBUG)
76 log_error ("%s(%d): non-null pointer", file
, line
);
77 #if defined (POINTER_DEBUG)
80 *ptr
= (struct group
*)0;
84 *ptr
= dmalloc (sizeof **ptr
, file
, line
);
86 memset (*ptr
, 0, sizeof **ptr
);
93 int group_reference (ptr
, bp
, file
, line
)
100 log_error ("%s(%d): null pointer", file
, line
);
101 #if defined (POINTER_DEBUG)
108 log_error ("%s(%d): non-null pointer", file
, line
);
109 #if defined (POINTER_DEBUG)
112 *ptr
= (struct group
*)0;
117 rc_register (file
, line
, ptr
, bp
, bp
-> refcnt
);
118 dmalloc_reuse (bp
, file
, line
, 1);
122 int group_dereference (ptr
, file
, line
)
131 log_error ("%s(%d): null pointer", file
, line
);
132 #if defined (POINTER_DEBUG)
140 *ptr
= (struct group
*)0;
142 rc_register (file
, line
, ptr
, group
, group
-> refcnt
);
143 if (group
-> refcnt
> 0)
146 if (group
-> refcnt
< 0) {
147 log_error ("%s(%d): negative refcnt!", file
, line
);
148 #if defined (DEBUG_RC_HISTORY)
151 #if defined (POINTER_DEBUG)
159 group_object_dereference (&group
-> object
, MDL
);
161 subnet_dereference (&group
-> subnet
, MDL
);
162 if (group
-> shared_network
)
163 shared_network_dereference (&group
-> shared_network
, MDL
);
164 if (group
-> statements
)
165 executable_statement_dereference (&group
-> statements
, MDL
);
166 dfree (group
, file
, line
);
170 struct dhcp_packet
*new_dhcp_packet (file
, line
)
174 struct dhcp_packet
*rval
;
175 rval
= (struct dhcp_packet
*)dmalloc (sizeof (struct dhcp_packet
),
180 struct hash_table
*new_hash_table (count
, file
, line
)
185 struct hash_table
*rval
= dmalloc (sizeof (struct hash_table
)
187 * sizeof (struct hash_bucket
*))
189 * sizeof (struct hash_bucket
*)),
191 rval
-> hash_count
= count
;
195 struct hash_bucket
*new_hash_bucket (file
, line
)
199 struct hash_bucket
*rval
= dmalloc (sizeof (struct hash_bucket
),
204 void free_hash_bucket (ptr
, file
, line
)
205 struct hash_bucket
*ptr
;
209 dfree ((VOIDPTR
)ptr
, file
, line
);
212 struct protocol
*new_protocol (file
, line
)
216 struct protocol
*rval
= dmalloc (sizeof (struct protocol
), file
, line
);
220 struct domain_search_list
*new_domain_search_list (file
, line
)
224 struct domain_search_list
*rval
=
225 dmalloc (sizeof (struct domain_search_list
), file
, line
);
229 struct name_server
*new_name_server (file
, line
)
233 struct name_server
*rval
=
234 dmalloc (sizeof (struct name_server
), file
, line
);
238 void free_name_server (ptr
, file
, line
)
239 struct name_server
*ptr
;
243 dfree ((VOIDPTR
)ptr
, file
, line
);
246 struct option
*new_option (file
, line
)
250 struct option
*rval
=
251 dmalloc (sizeof (struct option
), file
, line
);
253 memset (rval
, 0, sizeof *rval
);
257 void free_option (ptr
, file
, line
)
262 /* XXX have to put all options on heap before this is possible. */
265 dfree ((VOIDPTR
)option
-> name
, file
, line
);
266 dfree ((VOIDPTR
)ptr
, file
, line
);
270 struct universe
*new_universe (file
, line
)
274 struct universe
*rval
=
275 dmalloc (sizeof (struct universe
), file
, line
);
279 void free_universe (ptr
, file
, line
)
280 struct universe
*ptr
;
284 dfree ((VOIDPTR
)ptr
, file
, line
);
287 void free_domain_search_list (ptr
, file
, line
)
288 struct domain_search_list
*ptr
;
292 dfree ((VOIDPTR
)ptr
, file
, line
);
295 void free_protocol (ptr
, file
, line
)
296 struct protocol
*ptr
;
300 dfree ((VOIDPTR
)ptr
, file
, line
);
303 void free_hash_table (ptr
, file
, line
)
304 struct hash_table
*ptr
;
308 dfree ((VOIDPTR
)ptr
, file
, line
);
311 void free_dhcp_packet (ptr
, file
, line
)
312 struct dhcp_packet
*ptr
;
316 dfree ((VOIDPTR
)ptr
, file
, line
);
319 struct client_lease
*new_client_lease (file
, line
)
323 return (struct client_lease
*)dmalloc (sizeof (struct client_lease
),
327 void free_client_lease (lease
, file
, line
)
328 struct client_lease
*lease
;
332 dfree (lease
, file
, line
);
335 struct auth_key
*new_auth_key (len
, file
, line
)
340 struct auth_key
*peer
;
341 unsigned size
= len
- 1 + sizeof (struct auth_key
);
343 peer
= (struct auth_key
*)dmalloc (size
, file
, line
);
346 memset (peer
, 0, size
);
350 void free_auth_key (peer
, file
, line
)
351 struct auth_key
*peer
;
355 dfree (peer
, file
, line
);
360 pair
new_pair (file
, line
)
368 free_pairs
= foo
-> cdr
;
369 memset (foo
, 0, sizeof *foo
);
370 dmalloc_reuse (foo
, file
, line
, 0);
374 foo
= dmalloc (sizeof *foo
, file
, line
);
377 memset (foo
, 0, sizeof *foo
);
381 void free_pair (foo
, file
, line
)
386 foo
-> cdr
= free_pairs
;
388 dmalloc_reuse (free_pairs
, (char *)0, 0, 0);
391 struct expression
*free_expressions
;
393 int expression_allocate (cptr
, file
, line
)
394 struct expression
**cptr
;
398 struct expression
*rval
;
400 if (free_expressions
) {
401 rval
= free_expressions
;
402 free_expressions
= rval
-> data
.not;
404 rval
= dmalloc (sizeof (struct expression
), file
, line
);
408 memset (rval
, 0, sizeof *rval
);
409 return expression_reference (cptr
, rval
, file
, line
);
412 int expression_reference (ptr
, src
, file
, line
)
413 struct expression
**ptr
;
414 struct expression
*src
;
419 log_error ("%s(%d): null pointer", file
, line
);
420 #if defined (POINTER_DEBUG)
427 log_error ("%s(%d): non-null pointer", file
, line
);
428 #if defined (POINTER_DEBUG)
431 *ptr
= (struct expression
*)0;
436 rc_register (file
, line
, ptr
, src
, src
-> refcnt
);
437 dmalloc_reuse (src
, file
, line
, 1);
441 void free_expression (expr
, file
, line
)
442 struct expression
*expr
;
446 expr
-> data
.not = free_expressions
;
447 free_expressions
= expr
;
448 dmalloc_reuse (free_expressions
, (char *)0, 0, 0);
451 struct binding_value
*free_binding_values
;
453 int binding_value_allocate (cptr
, file
, line
)
454 struct binding_value
**cptr
;
458 struct binding_value
*rval
;
460 if (free_binding_values
) {
461 rval
= free_binding_values
;
462 free_binding_values
= rval
-> value
.bv
;
464 rval
= dmalloc (sizeof (struct binding_value
), file
, line
);
468 memset (rval
, 0, sizeof *rval
);
469 return binding_value_reference (cptr
, rval
, file
, line
);
472 int binding_value_reference (ptr
, src
, file
, line
)
473 struct binding_value
**ptr
;
474 struct binding_value
*src
;
479 log_error ("%s(%d): null pointer", file
, line
);
480 #if defined (POINTER_DEBUG)
487 log_error ("%s(%d): non-null pointer", file
, line
);
488 #if defined (POINTER_DEBUG)
491 *ptr
= (struct binding_value
*)0;
496 rc_register (file
, line
, ptr
, src
, src
-> refcnt
);
497 dmalloc_reuse (src
, file
, line
, 1);
501 void free_binding_value (bv
, file
, line
)
502 struct binding_value
*bv
;
506 bv
-> value
.bv
= free_binding_values
;
507 free_binding_values
= bv
;
508 dmalloc_reuse (free_binding_values
, (char *)0, 0, 0);
511 int fundef_allocate (cptr
, file
, line
)
512 struct fundef
**cptr
;
518 rval
= dmalloc (sizeof (struct fundef
), file
, line
);
521 memset (rval
, 0, sizeof *rval
);
522 return fundef_reference (cptr
, rval
, file
, line
);
525 int fundef_reference (ptr
, src
, file
, line
)
532 log_error ("%s(%d): null pointer", file
, line
);
533 #if defined (POINTER_DEBUG)
540 log_error ("%s(%d): non-null pointer", file
, line
);
541 #if defined (POINTER_DEBUG)
544 *ptr
= (struct fundef
*)0;
549 rc_register (file
, line
, ptr
, src
, src
-> refcnt
);
550 dmalloc_reuse (src
, file
, line
, 1);
554 struct option_cache
*free_option_caches
;
556 int option_cache_allocate (cptr
, file
, line
)
557 struct option_cache
**cptr
;
561 struct option_cache
*rval
;
563 if (free_option_caches
) {
564 rval
= free_option_caches
;
566 (struct option_cache
*)(rval
-> expression
);
567 dmalloc_reuse (rval
, file
, line
, 0);
569 rval
= dmalloc (sizeof (struct option_cache
), file
, line
);
573 memset (rval
, 0, sizeof *rval
);
574 return option_cache_reference (cptr
, rval
, file
, line
);
577 int option_cache_reference (ptr
, src
, file
, line
)
578 struct option_cache
**ptr
;
579 struct option_cache
*src
;
584 log_error ("%s(%d): null pointer", file
, line
);
585 #if defined (POINTER_DEBUG)
592 log_error ("%s(%d): non-null pointer", file
, line
);
593 #if defined (POINTER_DEBUG)
596 *ptr
= (struct option_cache
*)0;
601 rc_register (file
, line
, ptr
, src
, src
-> refcnt
);
602 dmalloc_reuse (src
, file
, line
, 1);
606 int buffer_allocate (ptr
, len
, file
, line
)
614 bp
= dmalloc (len
+ sizeof *bp
, file
, line
);
617 memset (bp
, 0, sizeof *bp
);
619 return buffer_reference (ptr
, bp
, file
, line
);
622 int buffer_reference (ptr
, bp
, file
, line
)
629 log_error ("%s(%d): null pointer", file
, line
);
630 #if defined (POINTER_DEBUG)
637 log_error ("%s(%d): non-null pointer", file
, line
);
638 #if defined (POINTER_DEBUG)
641 *ptr
= (struct buffer
*)0;
646 rc_register (file
, line
, ptr
, bp
, bp
-> refcnt
);
647 dmalloc_reuse (bp
, file
, line
, 1);
651 int buffer_dereference (ptr
, file
, line
)
659 log_error ("%s(%d): null pointer", file
, line
);
660 #if defined (POINTER_DEBUG)
668 log_error ("%s(%d): null pointer", file
, line
);
669 #if defined (POINTER_DEBUG)
677 rc_register (file
, line
, ptr
, *ptr
, (*ptr
) -> refcnt
);
678 if (!(*ptr
) -> refcnt
)
679 dfree ((*ptr
), file
, line
);
680 if ((*ptr
) -> refcnt
< 0) {
681 log_error ("%s(%d): negative refcnt!", file
, line
);
682 #if defined (DEBUG_RC_HISTORY)
685 #if defined (POINTER_DEBUG)
691 *ptr
= (struct buffer
*)0;
695 int dns_host_entry_allocate (ptr
, hostname
, file
, line
)
696 struct dns_host_entry
**ptr
;
697 const char *hostname
;
701 struct dns_host_entry
*bp
;
703 bp
= dmalloc (strlen (hostname
) + sizeof *bp
, file
, line
);
706 memset (bp
, 0, sizeof *bp
);
708 strcpy (bp
-> hostname
, hostname
);
709 return dns_host_entry_reference (ptr
, bp
, file
, line
);
712 int dns_host_entry_reference (ptr
, bp
, file
, line
)
713 struct dns_host_entry
**ptr
;
714 struct dns_host_entry
*bp
;
719 log_error ("%s(%d): null pointer", file
, line
);
720 #if defined (POINTER_DEBUG)
727 log_error ("%s(%d): non-null pointer", file
, line
);
728 #if defined (POINTER_DEBUG)
731 *ptr
= (struct dns_host_entry
*)0;
736 rc_register (file
, line
, ptr
, bp
, bp
-> refcnt
);
737 dmalloc_reuse (bp
, file
, line
, 1);
741 int dns_host_entry_dereference (ptr
, file
, line
)
742 struct dns_host_entry
**ptr
;
746 struct dns_host_entry
*bp
;
749 log_error ("%s(%d): null pointer", file
, line
);
750 #if defined (POINTER_DEBUG)
758 rc_register (file
, line
, ptr
, bp
, bp
-> refcnt
);
759 if (!(*ptr
) -> refcnt
)
760 dfree ((*ptr
), file
, line
);
761 if ((*ptr
) -> refcnt
< 0) {
762 log_error ("%s(%d): negative refcnt!", file
, line
);
763 #if defined (DEBUG_RC_HISTORY)
766 #if defined (POINTER_DEBUG)
772 *ptr
= (struct dns_host_entry
*)0;
776 int option_state_allocate (ptr
, file
, line
)
777 struct option_state
**ptr
;
784 log_error ("%s(%d): null pointer", file
, line
);
785 #if defined (POINTER_DEBUG)
792 log_error ("%s(%d): non-null pointer", file
, line
);
793 #if defined (POINTER_DEBUG)
796 *ptr
= (struct option_state
*)0;
800 size
= sizeof **ptr
+ (universe_count
- 1) * sizeof (VOIDPTR
);
801 *ptr
= dmalloc (size
, file
, line
);
803 memset (*ptr
, 0, size
);
804 (*ptr
) -> universe_count
= universe_count
;
805 (*ptr
) -> refcnt
= 1;
806 rc_register (file
, line
, ptr
, *ptr
, (*ptr
) -> refcnt
);
812 int option_state_reference (ptr
, bp
, file
, line
)
813 struct option_state
**ptr
;
814 struct option_state
*bp
;
819 log_error ("%s(%d): null pointer", file
, line
);
820 #if defined (POINTER_DEBUG)
827 log_error ("%s(%d): non-null pointer", file
, line
);
828 #if defined (POINTER_DEBUG)
831 *ptr
= (struct option_state
*)0;
836 rc_register (file
, line
, ptr
, bp
, bp
-> refcnt
);
837 dmalloc_reuse (bp
, file
, line
, 1);
841 int option_state_dereference (ptr
, file
, line
)
842 struct option_state
**ptr
;
847 struct option_state
*options
;
850 log_error ("%s(%d): null pointer", file
, line
);
851 #if defined (POINTER_DEBUG)
859 *ptr
= (struct option_state
*)0;
861 rc_register (file
, line
, ptr
, options
, options
-> refcnt
);
862 if (options
-> refcnt
> 0)
865 if (options
-> refcnt
< 0) {
866 log_error ("%s(%d): negative refcnt!", file
, line
);
867 #if defined (DEBUG_RC_HISTORY)
870 #if defined (POINTER_DEBUG)
877 /* Loop through the per-universe state. */
878 for (i
= 0; i
< options
-> universe_count
; i
++)
879 if (options
-> universes
[i
] &&
880 universes
[i
] -> option_state_dereference
)
881 ((*(universes
[i
] -> option_state_dereference
))
882 (universes
[i
], options
, file
, line
));
883 dfree (options
, file
, line
);
887 int executable_statement_allocate (ptr
, file
, line
)
888 struct executable_statement
**ptr
;
892 struct executable_statement
*bp
;
894 bp
= dmalloc (sizeof *bp
, file
, line
);
897 memset (bp
, 0, sizeof *bp
);
898 return executable_statement_reference (ptr
, bp
, file
, line
);
901 int executable_statement_reference (ptr
, bp
, file
, line
)
902 struct executable_statement
**ptr
;
903 struct executable_statement
*bp
;
908 log_error ("%s(%d): null pointer", file
, line
);
909 #if defined (POINTER_DEBUG)
916 log_error ("%s(%d): non-null pointer", file
, line
);
917 #if defined (POINTER_DEBUG)
920 *ptr
= (struct executable_statement
*)0;
925 rc_register (file
, line
, ptr
, bp
, bp
-> refcnt
);
926 dmalloc_reuse (bp
, file
, line
, 1);
930 static struct packet
*free_packets
;
932 int packet_allocate (ptr
, file
, line
)
940 log_error ("%s(%d): null pointer", file
, line
);
941 #if defined (POINTER_DEBUG)
948 log_error ("%s(%d): non-null pointer", file
, line
);
949 #if defined (POINTER_DEBUG)
952 *ptr
= (struct packet
*)0;
958 free_packets
= (struct packet
*)((*ptr
) -> raw
);
960 *ptr
= dmalloc (sizeof **ptr
, file
, line
);
963 memset (*ptr
, 0, sizeof **ptr
);
964 (*ptr
) -> refcnt
= 1;
970 int packet_reference (ptr
, bp
, file
, line
)
977 log_error ("%s(%d): null pointer", file
, line
);
978 #if defined (POINTER_DEBUG)
985 log_error ("%s(%d): non-null pointer", file
, line
);
986 #if defined (POINTER_DEBUG)
989 *ptr
= (struct packet
*)0;
994 rc_register (file
, line
, ptr
, bp
, bp
-> refcnt
);
995 dmalloc_reuse (bp
, file
, line
, 1);
999 int packet_dereference (ptr
, file
, line
)
1000 struct packet
**ptr
;
1005 struct packet
*packet
;
1007 if (!ptr
|| !*ptr
) {
1008 log_error ("%s(%d): null pointer", file
, line
);
1009 #if defined (POINTER_DEBUG)
1017 *ptr
= (struct packet
*)0;
1019 rc_register (file
, line
, ptr
, packet
, packet
-> refcnt
);
1020 if (packet
-> refcnt
> 0)
1023 if (packet
-> refcnt
< 0) {
1024 log_error ("%s(%d): negative refcnt!", file
, line
);
1025 #if defined (DEBUG_RC_HISTORY)
1028 #if defined (POINTER_DEBUG)
1035 if (packet
-> options
)
1036 option_state_dereference (&packet
-> options
, file
, line
);
1037 if (packet
-> interface
)
1038 interface_dereference (&packet
-> interface
, MDL
);
1039 packet
-> raw
= (struct dhcp_packet
*)free_packets
;
1040 free_packets
= packet
;
1041 dmalloc_reuse (free_packets
, (char *)0, 0, 0);
1045 int tsig_key_allocate (ptr
, file
, line
)
1046 struct tsig_key
**ptr
;
1053 log_error ("%s(%d): null pointer", file
, line
);
1054 #if defined (POINTER_DEBUG)
1061 log_error ("%s(%d): non-null pointer", file
, line
);
1062 #if defined (POINTER_DEBUG)
1065 *ptr
= (struct tsig_key
*)0;
1069 *ptr
= dmalloc (sizeof **ptr
, file
, line
);
1071 memset (*ptr
, 0, sizeof **ptr
);
1072 (*ptr
) -> refcnt
= 1;
1078 int tsig_key_reference (ptr
, bp
, file
, line
)
1079 struct tsig_key
**ptr
;
1080 struct tsig_key
*bp
;
1085 log_error ("%s(%d): null pointer", file
, line
);
1086 #if defined (POINTER_DEBUG)
1093 log_error ("%s(%d): non-null pointer", file
, line
);
1094 #if defined (POINTER_DEBUG)
1097 *ptr
= (struct tsig_key
*)0;
1102 rc_register (file
, line
, ptr
, bp
, bp
-> refcnt
);
1103 dmalloc_reuse (bp
, file
, line
, 1);
1107 int tsig_key_dereference (ptr
, file
, line
)
1108 struct tsig_key
**ptr
;
1113 struct tsig_key
*tsig_key
;
1115 if (!ptr
|| !*ptr
) {
1116 log_error ("%s(%d): null pointer", file
, line
);
1117 #if defined (POINTER_DEBUG)
1125 *ptr
= (struct tsig_key
*)0;
1126 --tsig_key
-> refcnt
;
1127 rc_register (file
, line
, ptr
, tsig_key
, tsig_key
-> refcnt
);
1128 if (tsig_key
-> refcnt
> 0)
1131 if (tsig_key
-> refcnt
< 0) {
1132 log_error ("%s(%d): negative refcnt!", file
, line
);
1133 #if defined (DEBUG_RC_HISTORY)
1136 #if defined (POINTER_DEBUG)
1143 if (tsig_key
-> name
)
1144 dfree (tsig_key
-> name
, file
, line
);
1145 if (tsig_key
-> algorithm
)
1146 dfree (tsig_key
-> algorithm
, file
, line
);
1147 if (tsig_key
-> key
.buffer
)
1148 data_string_forget (&tsig_key
-> key
, file
, line
);
1149 dfree (tsig_key
, file
, line
);
1153 int dns_zone_allocate (ptr
, file
, line
)
1154 struct dns_zone
**ptr
;
1161 log_error ("%s(%d): null pointer", file
, line
);
1162 #if defined (POINTER_DEBUG)
1169 log_error ("%s(%d): non-null pointer", file
, line
);
1170 #if defined (POINTER_DEBUG)
1173 *ptr
= (struct dns_zone
*)0;
1177 *ptr
= dmalloc (sizeof **ptr
, file
, line
);
1179 memset (*ptr
, 0, sizeof **ptr
);
1180 (*ptr
) -> refcnt
= 1;
1186 int dns_zone_reference (ptr
, bp
, file
, line
)
1187 struct dns_zone
**ptr
;
1188 struct dns_zone
*bp
;
1193 log_error ("%s(%d): null pointer", file
, line
);
1194 #if defined (POINTER_DEBUG)
1201 log_error ("%s(%d): non-null pointer", file
, line
);
1202 #if defined (POINTER_DEBUG)
1205 *ptr
= (struct dns_zone
*)0;
1210 rc_register (file
, line
, ptr
, bp
, bp
-> refcnt
);
1211 dmalloc_reuse (bp
, file
, line
, 1);
1215 int binding_scope_allocate (ptr
, file
, line
)
1216 struct binding_scope
**ptr
;
1220 struct binding_scope
*bp
;
1223 log_error ("%s(%d): null pointer", file
, line
);
1224 #if defined (POINTER_DEBUG)
1232 log_error ("%s(%d): non-null pointer", file
, line
);
1233 #if defined (POINTER_DEBUG)
1240 bp
= dmalloc (sizeof *bp
, file
, line
);
1243 memset (bp
, 0, sizeof *bp
);
1248 /* Make a copy of the data in data_string, upping the buffer reference
1249 count if there's a buffer. */
1251 void data_string_copy (dest
, src
, file
, line
)
1252 struct data_string
*dest
;
1253 struct data_string
*src
;
1258 buffer_reference (&dest
-> buffer
, src
-> buffer
, file
, line
);
1259 dest
-> data
= src
-> data
;
1260 dest
-> terminated
= src
-> terminated
;
1261 dest
-> len
= src
-> len
;
1264 /* Release the reference count to a data string's buffer (if any) and
1265 zero out the other information, yielding the null data string. */
1267 void data_string_forget (data
, file
, line
)
1268 struct data_string
*data
;
1273 buffer_dereference (&data
-> buffer
, file
, line
);
1274 memset (data
, 0, sizeof *data
);
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_truncate (dp
, len
)
1281 struct data_string
*dp
;
1284 if (len
< dp
-> len
) {
1285 dp
-> terminated
= 0;