]> git.ipfire.org Git - thirdparty/dhcp.git/blobdiff - server/salloc.c
Update RELNOTES
[thirdparty/dhcp.git] / server / salloc.c
index 9c0151414cad198ab708d0ca64870bb7aa06059d..791172e92b6926b120f631663156cb9143a4e917 100644 (file)
@@ -3,12 +3,12 @@
    Memory allocation for the DHCP server... */
 
 /*
- * Copyright (c) 2004-2007 by Internet Systems Consortium, Inc. ("ISC")
+ * Copyright (c) 2004-2017 by Internet Systems Consortium, Inc. ("ISC")
  * Copyright (c) 1996-2003 by Internet Software Consortium
  *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  *
  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  *
  *   Internet Systems Consortium, Inc.
- *   950 Charter Street
- *   Redwood City, CA 94063
+ *   PO Box 360
+ *   Newmarket, NH 03857 USA
  *   <info@isc.org>
  *   https://www.isc.org/
  *
- * This software has been written for Internet Systems Consortium
- * by Ted Lemon in cooperation with Vixie Enterprises and Nominum, Inc.
- * To learn more about Internet Systems Consortium, see
- * ``https://www.isc.org/''.  To learn more about Vixie Enterprises,
- * see ``http://www.vix.com''.   To learn more about Nominum, Inc., see
- * ``http://www.nominum.com''.
  */
 
 #include "dhcpd.h"
 #if defined (COMPACT_LEASES)
 struct lease *free_leases;
 
-# if defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
+#if defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
 struct lease *lease_hunks;
 
 void relinquish_lease_hunks ()
 {
-       struct lease *c, *n, **p, *f;
+       struct lease *c, *n, **p;
        int i;
 
        /* Account for all the leases on the free list. */
-       for (n = lease_hunks; n; n = n -> next) {
-           for (i = 1; i < n -> starts + 1; i++) {
+       for (n = lease_hunks; n; n = n->next) {
+           for (i = 1; i < n->starts + 1; i++) {
                p = &free_leases;
-               for (c = free_leases; c; c = c -> next) {
-                   if (c == &n [i]) {
-                       *p = c -> next;
-                       n -> ends++;
+               for (c = free_leases; c; c = c->next) {
+                   if (c == &n[i]) {
+                       *p = c->next;
+                       n->ends++;
                        break;
                    }
-                   p = &c -> next;
+                   p = &c->next;
                }
                if (!c) {
-                   log_info ("lease %s refcnt %d",
-                             piaddr (n [i].ip_addr), n [i].refcnt);
-                   dump_rc_history (&n [i]);
+                   log_info("lease %s refcnt %d",
+                            piaddr (n[i].ip_addr), n[i].refcnt);
+#if defined (DEBUG_RC_HISTORY)
+                   dump_rc_history(&n[i]);
+#endif
                }
            }
        }
-               
+
        for (c = lease_hunks; c; c = n) {
-               n = c -> next;
-               if (c -> ends != c -> starts) {
-                       log_info ("lease hunk %lx leases %ld free %ld",
-                                 (unsigned long)c, (unsigned long)c -> starts,
-                                 (unsigned long)c -> ends);
+               n = c->next;
+               if (c->ends != c->starts) {
+                       log_info("lease hunk %lx leases %ld free %ld",
+                                (unsigned long)c, (unsigned long)(c->starts),
+                                (unsigned long)(c->ends));
                }
-               dfree (c, MDL);
+               dfree(c, MDL);
        }
 
        /* Free all the rogue leases. */
        for (c = free_leases; c; c = n) {
-               n = c -> next;
-               dfree (c, MDL);
+               n = c->next;
+               dfree(c, MDL);
        }
 }
+
 #endif
 
 struct lease *new_leases (n, file, line)
@@ -92,11 +89,13 @@ struct lease *new_leases (n, file, line)
        struct lease *rval;
 #if defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
        rval = dmalloc ((n + 1) * sizeof (struct lease), file, line);
-       memset (rval, 0, sizeof (struct lease));
-       rval -> starts = n;
-       rval -> next = lease_hunks;
-       lease_hunks = rval;
-       rval++;
+       if (rval != NULL) {
+               memset (rval, 0, sizeof (struct lease));
+               rval -> starts = n;
+               rval -> next = lease_hunks;
+               lease_hunks = rval;
+               rval++;
+       }
 #else
        rval = dmalloc (n * sizeof (struct lease), file, line);
 #endif
@@ -111,7 +110,7 @@ isc_result_t dhcp_lease_free (omapi_object_t *lo,
 {
        struct lease *lease;
        if (lo -> type != dhcp_type_lease)
-               return ISC_R_INVALIDARG;
+               return DHCP_R_INVALIDARG;
        lease = (struct lease *)lo;
        memset (lease, 0, sizeof (struct lease));
        lease -> next = free_leases;