00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "dhcpd.h"
00031 #include <omapip/omapip_p.h>
00032
00033 struct dhcp_packet *dhcp_free_list;
00034 struct packet *packet_free_list;
00035
00036 int option_chain_head_allocate (ptr, file, line)
00037 struct option_chain_head **ptr;
00038 const char *file;
00039 int line;
00040 {
00041 struct option_chain_head *h;
00042
00043 if (!ptr) {
00044 log_error ("%s(%d): null pointer", file, line);
00045 #if defined (POINTER_DEBUG)
00046 abort ();
00047 #else
00048 return 0;
00049 #endif
00050 }
00051 if (*ptr) {
00052 log_error ("%s(%d): non-null pointer", file, line);
00053 #if defined (POINTER_DEBUG)
00054 abort ();
00055 #else
00056 *ptr = (struct option_chain_head *)0;
00057 #endif
00058 }
00059
00060 h = dmalloc (sizeof *h, file, line);
00061 if (h) {
00062 memset (h, 0, sizeof *h);
00063 return option_chain_head_reference (ptr, h, file, line);
00064 }
00065 return 0;
00066 }
00067
00068 int option_chain_head_reference (ptr, bp, file, line)
00069 struct option_chain_head **ptr;
00070 struct option_chain_head *bp;
00071 const char *file;
00072 int line;
00073 {
00074 if (!ptr) {
00075 log_error ("%s(%d): null pointer", file, line);
00076 #if defined (POINTER_DEBUG)
00077 abort ();
00078 #else
00079 return 0;
00080 #endif
00081 }
00082 if (*ptr) {
00083 log_error ("%s(%d): non-null pointer", file, line);
00084 #if defined (POINTER_DEBUG)
00085 abort ();
00086 #else
00087 *ptr = (struct option_chain_head *)0;
00088 #endif
00089 }
00090 *ptr = bp;
00091 bp -> refcnt++;
00092 rc_register (file, line, ptr, bp, bp -> refcnt, 0, RC_MISC);
00093 return 1;
00094 }
00095
00096 int option_chain_head_dereference (ptr, file, line)
00097 struct option_chain_head **ptr;
00098 const char *file;
00099 int line;
00100 {
00101 struct option_chain_head *option_chain_head;
00102 pair car, cdr;
00103
00104 if (!ptr || !*ptr) {
00105 log_error ("%s(%d): null pointer", file, line);
00106 #if defined (POINTER_DEBUG)
00107 abort ();
00108 #else
00109 return 0;
00110 #endif
00111 }
00112
00113 option_chain_head = *ptr;
00114 *ptr = (struct option_chain_head *)0;
00115 --option_chain_head -> refcnt;
00116 rc_register (file, line, ptr, option_chain_head,
00117 option_chain_head -> refcnt, 1, RC_MISC);
00118 if (option_chain_head -> refcnt > 0)
00119 return 1;
00120
00121 if (option_chain_head -> refcnt < 0) {
00122 log_error ("%s(%d): negative refcnt!", file, line);
00123 #if defined (DEBUG_RC_HISTORY)
00124 dump_rc_history (option_chain_head);
00125 #endif
00126 #if defined (POINTER_DEBUG)
00127 abort ();
00128 #else
00129 return 0;
00130 #endif
00131 }
00132
00133
00134 for (car = option_chain_head -> first; car; car = cdr) {
00135 cdr = car -> cdr;
00136 if (car -> car)
00137 option_cache_dereference ((struct option_cache **)
00138 (&car -> car), MDL);
00139 dfree (car, MDL);
00140 }
00141
00142 dfree (option_chain_head, file, line);
00143 return 1;
00144 }
00145
00146 int group_allocate (ptr, file, line)
00147 struct group **ptr;
00148 const char *file;
00149 int line;
00150 {
00151 struct group *g;
00152
00153 if (!ptr) {
00154 log_error ("%s(%d): null pointer", file, line);
00155 #if defined (POINTER_DEBUG)
00156 abort ();
00157 #else
00158 return 0;
00159 #endif
00160 }
00161 if (*ptr) {
00162 log_error ("%s(%d): non-null pointer", file, line);
00163 #if defined (POINTER_DEBUG)
00164 abort ();
00165 #else
00166 *ptr = (struct group *)0;
00167 #endif
00168 }
00169
00170 g = dmalloc (sizeof *g, file, line);
00171 if (g) {
00172 memset (g, 0, sizeof *g);
00173 return group_reference (ptr, g, file, line);
00174 }
00175 return 0;
00176 }
00177
00178 int group_reference (ptr, bp, file, line)
00179 struct group **ptr;
00180 struct group *bp;
00181 const char *file;
00182 int line;
00183 {
00184 if (!ptr) {
00185 log_error ("%s(%d): null pointer", file, line);
00186 #if defined (POINTER_DEBUG)
00187 abort ();
00188 #else
00189 return 0;
00190 #endif
00191 }
00192 if (*ptr) {
00193 log_error ("%s(%d): non-null pointer", file, line);
00194 #if defined (POINTER_DEBUG)
00195 abort ();
00196 #else
00197 *ptr = (struct group *)0;
00198 #endif
00199 }
00200 *ptr = bp;
00201 bp -> refcnt++;
00202 rc_register (file, line, ptr, bp, bp -> refcnt, 0, RC_MISC);
00203 return 1;
00204 }
00205
00206 int group_dereference (ptr, file, line)
00207 struct group **ptr;
00208 const char *file;
00209 int line;
00210 {
00211 struct group *group;
00212
00213 if (!ptr || !*ptr) {
00214 log_error ("%s(%d): null pointer", file, line);
00215 #if defined (POINTER_DEBUG)
00216 abort ();
00217 #else
00218 return 0;
00219 #endif
00220 }
00221
00222 group = *ptr;
00223 *ptr = (struct group *)0;
00224 --group -> refcnt;
00225 rc_register (file, line, ptr, group, group -> refcnt, 1, RC_MISC);
00226 if (group -> refcnt > 0)
00227 return 1;
00228
00229 if (group -> refcnt < 0) {
00230 log_error ("%s(%d): negative refcnt!", file, line);
00231 #if defined (DEBUG_RC_HISTORY)
00232 dump_rc_history (group);
00233 #endif
00234 #if defined (POINTER_DEBUG)
00235 abort ();
00236 #else
00237 return 0;
00238 #endif
00239 }
00240
00241 if (group -> object)
00242 group_object_dereference (&group -> object, file, line);
00243 if (group -> subnet)
00244 subnet_dereference (&group -> subnet, file, line);
00245 if (group -> shared_network)
00246 shared_network_dereference (&group -> shared_network,
00247 file, line);
00248 if (group -> statements)
00249 executable_statement_dereference (&group -> statements,
00250 file, line);
00251 if (group -> next)
00252 group_dereference (&group -> next, file, line);
00253 dfree (group, file, line);
00254 return 1;
00255 }
00256
00257 struct dhcp_packet *new_dhcp_packet (file, line)
00258 const char *file;
00259 int line;
00260 {
00261 struct dhcp_packet *rval;
00262 rval = (struct dhcp_packet *)dmalloc (sizeof (struct dhcp_packet),
00263 file, line);
00264 return rval;
00265 }
00266
00267 struct protocol *new_protocol (file, line)
00268 const char *file;
00269 int line;
00270 {
00271 struct protocol *rval = dmalloc (sizeof (struct protocol), file, line);
00272 return rval;
00273 }
00274
00275 struct domain_search_list *new_domain_search_list (file, line)
00276 const char *file;
00277 int line;
00278 {
00279 struct domain_search_list *rval =
00280 dmalloc (sizeof (struct domain_search_list), file, line);
00281 return rval;
00282 }
00283
00284 struct name_server *new_name_server (file, line)
00285 const char *file;
00286 int line;
00287 {
00288 struct name_server *rval =
00289 dmalloc (sizeof (struct name_server), file, line);
00290 return rval;
00291 }
00292
00293 void free_name_server (ptr, file, line)
00294 struct name_server *ptr;
00295 const char *file;
00296 int line;
00297 {
00298 dfree ((void *)ptr, file, line);
00299 }
00300
00301 struct option *new_option (name, file, line)
00302 const char *name;
00303 const char *file;
00304 int line;
00305 {
00306 struct option *rval;
00307 int len;
00308
00309 len = strlen(name);
00310
00311 rval = dmalloc(sizeof(struct option) + len + 1, file, line);
00312
00313 if(rval) {
00314 memcpy(rval + 1, name, len);
00315 rval->name = (char *)(rval + 1);
00316 }
00317
00318 return rval;
00319 }
00320
00321 struct universe *new_universe (file, line)
00322 const char *file;
00323 int line;
00324 {
00325 struct universe *rval =
00326 dmalloc (sizeof (struct universe), file, line);
00327 return rval;
00328 }
00329
00330 void free_universe (ptr, file, line)
00331 struct universe *ptr;
00332 const char *file;
00333 int line;
00334 {
00335 dfree ((void *)ptr, file, line);
00336 }
00337
00338 void free_domain_search_list (ptr, file, line)
00339 struct domain_search_list *ptr;
00340 const char *file;
00341 int line;
00342 {
00343 dfree ((void *)ptr, file, line);
00344 }
00345
00346 void free_protocol (ptr, file, line)
00347 struct protocol *ptr;
00348 const char *file;
00349 int line;
00350 {
00351 dfree ((void *)ptr, file, line);
00352 }
00353
00354 void free_dhcp_packet (ptr, file, line)
00355 struct dhcp_packet *ptr;
00356 const char *file;
00357 int line;
00358 {
00359 dfree ((void *)ptr, file, line);
00360 }
00361
00362 struct client_lease *new_client_lease (file, line)
00363 const char *file;
00364 int line;
00365 {
00366 return (struct client_lease *)dmalloc (sizeof (struct client_lease),
00367 file, line);
00368 }
00369
00370 void free_client_lease (lease, file, line)
00371 struct client_lease *lease;
00372 const char *file;
00373 int line;
00374 {
00375 dfree (lease, file, line);
00376 }
00377
00378 pair free_pairs;
00379
00380 pair new_pair (file, line)
00381 const char *file;
00382 int line;
00383 {
00384 pair foo;
00385
00386 if (free_pairs) {
00387 foo = free_pairs;
00388 free_pairs = foo -> cdr;
00389 memset (foo, 0, sizeof *foo);
00390 dmalloc_reuse (foo, file, line, 0);
00391 return foo;
00392 }
00393
00394 foo = dmalloc (sizeof *foo, file, line);
00395 if (!foo)
00396 return foo;
00397 memset (foo, 0, sizeof *foo);
00398 return foo;
00399 }
00400
00401 void free_pair (foo, file, line)
00402 pair foo;
00403 const char *file;
00404 int line;
00405 {
00406 foo -> cdr = free_pairs;
00407 free_pairs = foo;
00408 dmalloc_reuse (free_pairs, __FILE__, __LINE__, 0);
00409 }
00410
00411 #if defined (DEBUG_MEMORY_LEAKAGE) || \
00412 defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
00413 void relinquish_free_pairs ()
00414 {
00415 pair pf, pc;
00416
00417 for (pf = free_pairs; pf; pf = pc) {
00418 pc = pf -> cdr;
00419 dfree (pf, MDL);
00420 }
00421 free_pairs = (pair)0;
00422 }
00423 #endif
00424
00425 struct expression *free_expressions;
00426
00427 int expression_allocate (cptr, file, line)
00428 struct expression **cptr;
00429 const char *file;
00430 int line;
00431 {
00432 struct expression *rval;
00433
00434 if (free_expressions) {
00435 rval = free_expressions;
00436 free_expressions = rval -> data.not;
00437 dmalloc_reuse (rval, file, line, 1);
00438 } else {
00439 rval = dmalloc (sizeof (struct expression), file, line);
00440 if (!rval)
00441 return 0;
00442 }
00443 memset (rval, 0, sizeof *rval);
00444 return expression_reference (cptr, rval, file, line);
00445 }
00446
00447 int expression_reference (ptr, src, file, line)
00448 struct expression **ptr;
00449 struct expression *src;
00450 const char *file;
00451 int line;
00452 {
00453 if (!ptr) {
00454 log_error ("%s(%d): null pointer", file, line);
00455 #if defined (POINTER_DEBUG)
00456 abort ();
00457 #else
00458 return 0;
00459 #endif
00460 }
00461 if (*ptr) {
00462 log_error ("%s(%d): non-null pointer", file, line);
00463 #if defined (POINTER_DEBUG)
00464 abort ();
00465 #else
00466 *ptr = (struct expression *)0;
00467 #endif
00468 }
00469 *ptr = src;
00470 src -> refcnt++;
00471 rc_register (file, line, ptr, src, src -> refcnt, 0, RC_MISC);
00472 return 1;
00473 }
00474
00475 void free_expression (expr, file, line)
00476 struct expression *expr;
00477 const char *file;
00478 int line;
00479 {
00480 expr -> data.not = free_expressions;
00481 free_expressions = expr;
00482 dmalloc_reuse (free_expressions, __FILE__, __LINE__, 0);
00483 }
00484
00485 #if defined (DEBUG_MEMORY_LEAKAGE) || \
00486 defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
00487 void relinquish_free_expressions ()
00488 {
00489 struct expression *e, *n;
00490
00491 for (e = free_expressions; e; e = n) {
00492 n = e -> data.not;
00493 dfree (e, MDL);
00494 }
00495 free_expressions = (struct expression *)0;
00496 }
00497 #endif
00498
00499 struct binding_value *free_binding_values;
00500
00501 int binding_value_allocate (cptr, file, line)
00502 struct binding_value **cptr;
00503 const char *file;
00504 int line;
00505 {
00506 struct binding_value *rval;
00507
00508 if (free_binding_values) {
00509 rval = free_binding_values;
00510 free_binding_values = rval -> value.bv;
00511 dmalloc_reuse (rval, file, line, 1);
00512 } else {
00513 rval = dmalloc (sizeof (struct binding_value), file, line);
00514 if (!rval)
00515 return 0;
00516 }
00517 memset (rval, 0, sizeof *rval);
00518 return binding_value_reference (cptr, rval, file, line);
00519 }
00520
00521 int binding_value_reference (ptr, src, file, line)
00522 struct binding_value **ptr;
00523 struct binding_value *src;
00524 const char *file;
00525 int line;
00526 {
00527 if (!ptr) {
00528 log_error ("%s(%d): null pointer", file, line);
00529 #if defined (POINTER_DEBUG)
00530 abort ();
00531 #else
00532 return 0;
00533 #endif
00534 }
00535 if (*ptr) {
00536 log_error ("%s(%d): non-null pointer", file, line);
00537 #if defined (POINTER_DEBUG)
00538 abort ();
00539 #else
00540 *ptr = (struct binding_value *)0;
00541 #endif
00542 }
00543 *ptr = src;
00544 src -> refcnt++;
00545 rc_register (file, line, ptr, src, src -> refcnt, 0, RC_MISC);
00546 return 1;
00547 }
00548
00549 void free_binding_value (bv, file, line)
00550 struct binding_value *bv;
00551 const char *file;
00552 int line;
00553 {
00554 bv -> value.bv = free_binding_values;
00555 free_binding_values = bv;
00556 dmalloc_reuse (free_binding_values, (char *)0, 0, 0);
00557 }
00558
00559 #if defined (DEBUG_MEMORY_LEAKAGE) || \
00560 defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
00561 void relinquish_free_binding_values ()
00562 {
00563 struct binding_value *b, *n;
00564
00565 for (b = free_binding_values; b; b = n) {
00566 n = b -> value.bv;
00567 dfree (b, MDL);
00568 }
00569 free_binding_values = (struct binding_value *)0;
00570 }
00571 #endif
00572
00573 int fundef_allocate (cptr, file, line)
00574 struct fundef **cptr;
00575 const char *file;
00576 int line;
00577 {
00578 struct fundef *rval;
00579
00580 rval = dmalloc (sizeof (struct fundef), file, line);
00581 if (!rval)
00582 return 0;
00583 memset (rval, 0, sizeof *rval);
00584 return fundef_reference (cptr, rval, file, line);
00585 }
00586
00587 int fundef_reference (ptr, src, file, line)
00588 struct fundef **ptr;
00589 struct fundef *src;
00590 const char *file;
00591 int line;
00592 {
00593 if (!ptr) {
00594 log_error ("%s(%d): null pointer", file, line);
00595 #if defined (POINTER_DEBUG)
00596 abort ();
00597 #else
00598 return 0;
00599 #endif
00600 }
00601 if (*ptr) {
00602 log_error ("%s(%d): non-null pointer", file, line);
00603 #if defined (POINTER_DEBUG)
00604 abort ();
00605 #else
00606 *ptr = (struct fundef *)0;
00607 #endif
00608 }
00609 *ptr = src;
00610 src -> refcnt++;
00611 rc_register (file, line, ptr, src, src -> refcnt, 0, RC_MISC);
00612 return 1;
00613 }
00614
00615 struct option_cache *free_option_caches;
00616
00617 #if defined (DEBUG_MEMORY_LEAKAGE) || \
00618 defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
00619 void relinquish_free_option_caches ()
00620 {
00621 struct option_cache *o, *n;
00622
00623 for (o = free_option_caches; o; o = n) {
00624 n = (struct option_cache *)(o -> expression);
00625 dfree (o, MDL);
00626 }
00627 free_option_caches = (struct option_cache *)0;
00628 }
00629 #endif
00630
00631 int option_cache_allocate (cptr, file, line)
00632 struct option_cache **cptr;
00633 const char *file;
00634 int line;
00635 {
00636 struct option_cache *rval;
00637
00638 if (free_option_caches) {
00639 rval = free_option_caches;
00640 free_option_caches =
00641 (struct option_cache *)(rval -> expression);
00642 dmalloc_reuse (rval, file, line, 0);
00643 } else {
00644 rval = dmalloc (sizeof (struct option_cache), file, line);
00645 if (!rval)
00646 return 0;
00647 }
00648 memset (rval, 0, sizeof *rval);
00649 return option_cache_reference (cptr, rval, file, line);
00650 }
00651
00652 int option_cache_reference (ptr, src, file, line)
00653 struct option_cache **ptr;
00654 struct option_cache *src;
00655 const char *file;
00656 int line;
00657 {
00658 if (!ptr) {
00659 log_error ("%s(%d): null pointer", file, line);
00660 #if defined (POINTER_DEBUG)
00661 abort ();
00662 #else
00663 return 0;
00664 #endif
00665 }
00666 if (*ptr) {
00667 log_error ("%s(%d): non-null pointer", file, line);
00668 #if defined (POINTER_DEBUG)
00669 abort ();
00670 #else
00671 *ptr = (struct option_cache *)0;
00672 #endif
00673 }
00674 *ptr = src;
00675 src -> refcnt++;
00676 rc_register (file, line, ptr, src, src -> refcnt, 0, RC_MISC);
00677 return 1;
00678 }
00679
00680 int buffer_allocate (ptr, len, file, line)
00681 struct buffer **ptr;
00682 unsigned len;
00683 const char *file;
00684 int line;
00685 {
00686 struct buffer *bp;
00687
00688
00689
00690 bp = dmalloc (len + sizeof *bp, file, line);
00691 if (!bp)
00692 return 0;
00693
00694 memset (bp, 0, sizeof *bp);
00695 bp -> refcnt = 0;
00696 return buffer_reference (ptr, bp, file, line);
00697 }
00698
00699 int buffer_reference (ptr, bp, file, line)
00700 struct buffer **ptr;
00701 struct buffer *bp;
00702 const char *file;
00703 int line;
00704 {
00705 if (!ptr) {
00706 log_error ("%s(%d): null pointer", file, line);
00707 #if defined (POINTER_DEBUG)
00708 abort ();
00709 #else
00710 return 0;
00711 #endif
00712 }
00713 if (*ptr) {
00714 log_error ("%s(%d): non-null pointer", file, line);
00715 #if defined (POINTER_DEBUG)
00716 abort ();
00717 #else
00718 *ptr = (struct buffer *)0;
00719 #endif
00720 }
00721 *ptr = bp;
00722 bp -> refcnt++;
00723 rc_register (file, line, ptr, bp, bp -> refcnt, 0, RC_MISC);
00724 return 1;
00725 }
00726
00727 int buffer_dereference (ptr, file, line)
00728 struct buffer **ptr;
00729 const char *file;
00730 int line;
00731 {
00732 if (!ptr) {
00733 log_error ("%s(%d): null pointer", file, line);
00734 #if defined (POINTER_DEBUG)
00735 abort ();
00736 #else
00737 return 0;
00738 #endif
00739 }
00740
00741 if (!*ptr) {
00742 log_error ("%s(%d): null pointer", file, line);
00743 #if defined (POINTER_DEBUG)
00744 abort ();
00745 #else
00746 return 0;
00747 #endif
00748 }
00749
00750 (*ptr) -> refcnt--;
00751 rc_register (file, line, ptr, *ptr, (*ptr) -> refcnt, 1, RC_MISC);
00752 if (!(*ptr) -> refcnt) {
00753 dfree ((*ptr), file, line);
00754 } else if ((*ptr) -> refcnt < 0) {
00755 log_error ("%s(%d): negative refcnt!", file, line);
00756 #if defined (DEBUG_RC_HISTORY)
00757 dump_rc_history (*ptr);
00758 #endif
00759 #if defined (POINTER_DEBUG)
00760 abort ();
00761 #else
00762 return 0;
00763 #endif
00764 }
00765 *ptr = (struct buffer *)0;
00766 return 1;
00767 }
00768
00769 int dns_host_entry_allocate (ptr, hostname, file, line)
00770 struct dns_host_entry **ptr;
00771 const char *hostname;
00772 const char *file;
00773 int line;
00774 {
00775 struct dns_host_entry *bp;
00776
00777 bp = dmalloc (strlen (hostname) + sizeof *bp, file, line);
00778 if (!bp)
00779 return 0;
00780 memset (bp, 0, sizeof *bp);
00781 bp -> refcnt = 0;
00782 strcpy (bp -> hostname, hostname);
00783 return dns_host_entry_reference (ptr, bp, file, line);
00784 }
00785
00786 int dns_host_entry_reference (ptr, bp, file, line)
00787 struct dns_host_entry **ptr;
00788 struct dns_host_entry *bp;
00789 const char *file;
00790 int line;
00791 {
00792 if (!ptr) {
00793 log_error ("%s(%d): null pointer", file, line);
00794 #if defined (POINTER_DEBUG)
00795 abort ();
00796 #else
00797 return 0;
00798 #endif
00799 }
00800 if (*ptr) {
00801 log_error ("%s(%d): non-null pointer", file, line);
00802 #if defined (POINTER_DEBUG)
00803 abort ();
00804 #else
00805 *ptr = (struct dns_host_entry *)0;
00806 #endif
00807 }
00808 *ptr = bp;
00809 bp -> refcnt++;
00810 rc_register (file, line, ptr, bp, bp -> refcnt, 0, RC_MISC);
00811 return 1;
00812 }
00813
00814 int dns_host_entry_dereference (ptr, file, line)
00815 struct dns_host_entry **ptr;
00816 const char *file;
00817 int line;
00818 {
00819 if (!ptr || !*ptr) {
00820 log_error ("%s(%d): null pointer", file, line);
00821 #if defined (POINTER_DEBUG)
00822 abort ();
00823 #else
00824 return 0;
00825 #endif
00826 }
00827
00828 (*ptr)->refcnt--;
00829 rc_register (file, line, ptr, *ptr, (*ptr)->refcnt, 1, RC_MISC);
00830 if ((*ptr)->refcnt == 0) {
00831 dfree ((*ptr), file, line);
00832 } else if ((*ptr)->refcnt < 0) {
00833 log_error ("%s(%d): negative refcnt!", file, line);
00834 #if defined (DEBUG_RC_HISTORY)
00835 dump_rc_history (*ptr);
00836 #endif
00837 #if defined (POINTER_DEBUG)
00838 abort ();
00839 #else
00840 return 0;
00841 #endif
00842 }
00843 *ptr = (struct dns_host_entry *)0;
00844 return 1;
00845 }
00846
00847 int option_state_allocate (ptr, file, line)
00848 struct option_state **ptr;
00849 const char *file;
00850 int line;
00851 {
00852 unsigned size;
00853
00854 if (!ptr) {
00855 log_error ("%s(%d): null pointer", file, line);
00856 #if defined (POINTER_DEBUG)
00857 abort ();
00858 #else
00859 return 0;
00860 #endif
00861 }
00862 if (*ptr) {
00863 log_error ("%s(%d): non-null pointer", file, line);
00864 #if defined (POINTER_DEBUG)
00865 abort ();
00866 #else
00867 *ptr = (struct option_state *)0;
00868 #endif
00869 }
00870
00871 size = sizeof **ptr + (universe_count - 1) * sizeof (void *);
00872 *ptr = dmalloc (size, file, line);
00873 if (*ptr) {
00874 memset (*ptr, 0, size);
00875 (*ptr) -> universe_count = universe_count;
00876 (*ptr) -> refcnt = 1;
00877 rc_register (file, line,
00878 ptr, *ptr, (*ptr) -> refcnt, 0, RC_MISC);
00879 return 1;
00880 }
00881 return 0;
00882 }
00883
00884 int option_state_reference (ptr, bp, file, line)
00885 struct option_state **ptr;
00886 struct option_state *bp;
00887 const char *file;
00888 int line;
00889 {
00890 if (!ptr) {
00891 log_error ("%s(%d): null pointer", file, line);
00892 #if defined (POINTER_DEBUG)
00893 abort ();
00894 #else
00895 return 0;
00896 #endif
00897 }
00898 if (*ptr) {
00899 log_error ("%s(%d): non-null pointer", file, line);
00900 #if defined (POINTER_DEBUG)
00901 abort ();
00902 #else
00903 *ptr = (struct option_state *)0;
00904 #endif
00905 }
00906 *ptr = bp;
00907 bp -> refcnt++;
00908 rc_register (file, line, ptr, bp, bp -> refcnt, 0, RC_MISC);
00909 return 1;
00910 }
00911
00912 int option_state_dereference (ptr, file, line)
00913 struct option_state **ptr;
00914 const char *file;
00915 int line;
00916 {
00917 int i;
00918 struct option_state *options;
00919
00920 if (!ptr || !*ptr) {
00921 log_error ("%s(%d): null pointer", file, line);
00922 #if defined (POINTER_DEBUG)
00923 abort ();
00924 #else
00925 return 0;
00926 #endif
00927 }
00928
00929 options = *ptr;
00930 *ptr = (struct option_state *)0;
00931 --options -> refcnt;
00932 rc_register (file, line, ptr, options, options -> refcnt, 1, RC_MISC);
00933 if (options -> refcnt > 0)
00934 return 1;
00935
00936 if (options -> refcnt < 0) {
00937 log_error ("%s(%d): negative refcnt!", file, line);
00938 #if defined (DEBUG_RC_HISTORY)
00939 dump_rc_history (options);
00940 #endif
00941 #if defined (POINTER_DEBUG)
00942 abort ();
00943 #else
00944 return 0;
00945 #endif
00946 }
00947
00948
00949 for (i = 0; i < options -> universe_count; i++)
00950 if (options -> universes [i] &&
00951 universes [i] -> option_state_dereference)
00952 ((*(universes [i] -> option_state_dereference))
00953 (universes [i], options, file, line));
00954
00955 dfree (options, file, line);
00956 return 1;
00957 }
00958
00959 int executable_statement_allocate (ptr, file, line)
00960 struct executable_statement **ptr;
00961 const char *file;
00962 int line;
00963 {
00964 struct executable_statement *bp;
00965
00966 bp = dmalloc (sizeof *bp, file, line);
00967 if (!bp)
00968 return 0;
00969 memset (bp, 0, sizeof *bp);
00970 return executable_statement_reference (ptr, bp, file, line);
00971 }
00972
00973 int executable_statement_reference (ptr, bp, file, line)
00974 struct executable_statement **ptr;
00975 struct executable_statement *bp;
00976 const char *file;
00977 int line;
00978 {
00979 if (!ptr) {
00980 log_error ("%s(%d): null pointer", file, line);
00981 #if defined (POINTER_DEBUG)
00982 abort ();
00983 #else
00984 return 0;
00985 #endif
00986 }
00987 if (*ptr) {
00988 log_error ("%s(%d): non-null pointer", file, line);
00989 #if defined (POINTER_DEBUG)
00990 abort ();
00991 #else
00992 *ptr = (struct executable_statement *)0;
00993 #endif
00994 }
00995 *ptr = bp;
00996 bp -> refcnt++;
00997 rc_register (file, line, ptr, bp, bp -> refcnt, 0, RC_MISC);
00998 return 1;
00999 }
01000
01001 static struct packet *free_packets;
01002
01003 #if defined (DEBUG_MEMORY_LEAKAGE) || \
01004 defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
01005 void relinquish_free_packets ()
01006 {
01007 struct packet *p, *n;
01008 for (p = free_packets; p; p = n) {
01009 n = (struct packet *)(p -> raw);
01010 dfree (p, MDL);
01011 }
01012 free_packets = (struct packet *)0;
01013 }
01014 #endif
01015
01016 int packet_allocate (ptr, file, line)
01017 struct packet **ptr;
01018 const char *file;
01019 int line;
01020 {
01021 struct packet *p;
01022
01023 if (!ptr) {
01024 log_error ("%s(%d): null pointer", file, line);
01025 #if defined (POINTER_DEBUG)
01026 abort ();
01027 #else
01028 return 0;
01029 #endif
01030 }
01031 if (*ptr) {
01032 log_error ("%s(%d): non-null pointer", file, line);
01033 #if defined (POINTER_DEBUG)
01034 abort ();
01035 #else
01036 *ptr = (struct packet *)0;
01037 #endif
01038 }
01039
01040 if (free_packets) {
01041 p = free_packets;
01042 free_packets = (struct packet *)(p -> raw);
01043 dmalloc_reuse (p, file, line, 1);
01044 } else {
01045 p = dmalloc (sizeof *p, file, line);
01046 }
01047 if (p) {
01048 memset (p, 0, sizeof *p);
01049 return packet_reference (ptr, p, file, line);
01050 }
01051 return 0;
01052 }
01053
01054 int packet_reference (ptr, bp, file, line)
01055 struct packet **ptr;
01056 struct packet *bp;
01057 const char *file;
01058 int line;
01059 {
01060 if (!ptr) {
01061 log_error ("%s(%d): null pointer", file, line);
01062 #if defined (POINTER_DEBUG)
01063 abort ();
01064 #else
01065 return 0;
01066 #endif
01067 }
01068 if (*ptr) {
01069 log_error ("%s(%d): non-null pointer", file, line);
01070 #if defined (POINTER_DEBUG)
01071 abort ();
01072 #else
01073 *ptr = (struct packet *)0;
01074 #endif
01075 }
01076 *ptr = bp;
01077 bp -> refcnt++;
01078 rc_register (file, line, ptr, bp, bp -> refcnt, 0, RC_MISC);
01079 return 1;
01080 }
01081
01082 int packet_dereference (ptr, file, line)
01083 struct packet **ptr;
01084 const char *file;
01085 int line;
01086 {
01087 int i;
01088 struct packet *packet;
01089
01090 if (!ptr || !*ptr) {
01091 log_error ("%s(%d): null pointer", file, line);
01092 #if defined (POINTER_DEBUG)
01093 abort ();
01094 #else
01095 return 0;
01096 #endif
01097 }
01098
01099 packet = *ptr;
01100 *ptr = (struct packet *)0;
01101 --packet -> refcnt;
01102 rc_register (file, line, ptr, packet, packet -> refcnt, 1, RC_MISC);
01103 if (packet -> refcnt > 0)
01104 return 1;
01105
01106 if (packet -> refcnt < 0) {
01107 log_error ("%s(%d): negative refcnt!", file, line);
01108 #if defined (DEBUG_RC_HISTORY)
01109 dump_rc_history (packet);
01110 #endif
01111 #if defined (POINTER_DEBUG)
01112 abort ();
01113 #else
01114 return 0;
01115 #endif
01116 }
01117
01118 if (packet -> options)
01119 option_state_dereference (&packet -> options, file, line);
01120 if (packet -> interface)
01121 interface_dereference (&packet -> interface, MDL);
01122 if (packet -> shared_network)
01123 shared_network_dereference (&packet -> shared_network, MDL);
01124 for (i = 0; i < packet -> class_count && i < PACKET_MAX_CLASSES; i++) {
01125 if (packet -> classes [i])
01126 omapi_object_dereference ((omapi_object_t **)
01127 &packet -> classes [i], MDL);
01128 }
01129 packet -> raw = (struct dhcp_packet *)free_packets;
01130 free_packets = packet;
01131 dmalloc_reuse (free_packets, __FILE__, __LINE__, 0);
01132 return 1;
01133 }
01134
01135 int dns_zone_allocate (ptr, file, line)
01136 struct dns_zone **ptr;
01137 const char *file;
01138 int line;
01139 {
01140 struct dns_zone *d;
01141
01142 if (!ptr) {
01143 log_error ("%s(%d): null pointer", file, line);
01144 #if defined (POINTER_DEBUG)
01145 abort ();
01146 #else
01147 return 0;
01148 #endif
01149 }
01150 if (*ptr) {
01151 log_error ("%s(%d): non-null pointer", file, line);
01152 #if defined (POINTER_DEBUG)
01153 abort ();
01154 #else
01155 *ptr = (struct dns_zone *)0;
01156 #endif
01157 }
01158
01159 d = dmalloc (sizeof *d, file, line);
01160 if (d) {
01161 memset (d, 0, sizeof *d);
01162 return dns_zone_reference (ptr, d, file, line);
01163 }
01164 return 0;
01165 }
01166
01167 int dns_zone_reference (ptr, bp, file, line)
01168 struct dns_zone **ptr;
01169 struct dns_zone *bp;
01170 const char *file;
01171 int line;
01172 {
01173 if (!ptr) {
01174 log_error ("%s(%d): null pointer", file, line);
01175 #if defined (POINTER_DEBUG)
01176 abort ();
01177 #else
01178 return 0;
01179 #endif
01180 }
01181 if (*ptr) {
01182 log_error ("%s(%d): non-null pointer", file, line);
01183 #if defined (POINTER_DEBUG)
01184 abort ();
01185 #else
01186 *ptr = (struct dns_zone *)0;
01187 #endif
01188 }
01189 *ptr = bp;
01190 bp -> refcnt++;
01191 rc_register (file, line, ptr, bp, bp -> refcnt, 0, RC_MISC);
01192 return 1;
01193 }
01194
01195 int binding_scope_allocate (ptr, file, line)
01196 struct binding_scope **ptr;
01197 const char *file;
01198 int line;
01199 {
01200 struct binding_scope *bp;
01201
01202 if (!ptr) {
01203 log_error ("%s(%d): null pointer", file, line);
01204 #if defined (POINTER_DEBUG)
01205 abort ();
01206 #else
01207 return 0;
01208 #endif
01209 }
01210
01211 if (*ptr) {
01212 log_error ("%s(%d): non-null pointer", file, line);
01213 #if defined (POINTER_DEBUG)
01214 abort ();
01215 #else
01216 return 0;
01217 #endif
01218 }
01219
01220 bp = dmalloc (sizeof *bp, file, line);
01221 if (!bp)
01222 return 0;
01223 memset (bp, 0, sizeof *bp);
01224 binding_scope_reference (ptr, bp, file, line);
01225 return 1;
01226 }
01227
01228 int binding_scope_reference (ptr, bp, file, line)
01229 struct binding_scope **ptr;
01230 struct binding_scope *bp;
01231 const char *file;
01232 int line;
01233 {
01234 if (!ptr) {
01235 log_error ("%s(%d): null pointer", file, line);
01236 #if defined (POINTER_DEBUG)
01237 abort ();
01238 #else
01239 return 0;
01240 #endif
01241 }
01242 if (*ptr) {
01243 log_error ("%s(%d): non-null pointer", file, line);
01244 #if defined (POINTER_DEBUG)
01245 abort ();
01246 #else
01247 *ptr = (struct binding_scope *)0;
01248 #endif
01249 }
01250 *ptr = bp;
01251 bp -> refcnt++;
01252 rc_register (file, line, ptr, bp, bp -> refcnt, 0, RC_MISC);
01253 return 1;
01254 }
01255
01256
01257
01258
01259 void
01260 data_string_copy(struct data_string *dest, const struct data_string *src,
01261 const char *file, int line)
01262 {
01263 if (src -> buffer) {
01264 buffer_reference (&dest -> buffer, src -> buffer, file, line);
01265 } else {
01266 dest->buffer = NULL;
01267 }
01268 dest -> data = src -> data;
01269 dest -> terminated = src -> terminated;
01270 dest -> len = src -> len;
01271 }
01272
01273
01274
01275
01276 void data_string_forget (data, file, line)
01277 struct data_string *data;
01278 const char *file;
01279 int line;
01280 {
01281 if (data -> buffer)
01282 buffer_dereference (&data -> buffer, file, line);
01283 memset (data, 0, sizeof *data);
01284 }
01285
01286
01287
01288
01289 void data_string_truncate (dp, len)
01290 struct data_string *dp;
01291 int len;
01292 {
01293
01294 if (len < dp -> len) {
01295 dp -> terminated = 0;
01296 dp -> len = len;
01297 }
01298 }