diff options
author | Hans Dedecker <dedeckeh@gmail.com> | 2019-05-14 16:18:51 +0200 |
---|---|---|
committer | Hans Dedecker <dedeckeh@gmail.com> | 2019-05-15 10:10:08 +0200 |
commit | c0c8034bc17519c7960f40f6d796b5485cfc4cdb (patch) | |
tree | ef3079b303164e2c5313a89e97e4d8e4d6aed4b1 /src/odhcpd.h | |
parent | f98b7ee899d492d32c4d857aa068daf95ae5be7b (diff) |
treewide: init assignment lists head
When allocating an assignment in alloc_assignment; init the circular head
and lease_list circular lists. Avoids checking NULL pointer when freeing
the assignment in free_assignment.
Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
Diffstat (limited to 'src/odhcpd.h')
-rw-r--r-- | src/odhcpd.h | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/src/odhcpd.h b/src/odhcpd.h index 9535e75..37a5a4a 100644 --- a/src/odhcpd.h +++ b/src/odhcpd.h @@ -309,11 +309,8 @@ extern struct avl_tree interfaces; inline static void free_assignment(struct dhcp_assignment *a) { - if (a->head.next) - list_del(&a->head); - - if (a->lease_list.next) - list_del(&a->lease_list); + list_del(&a->head); + list_del(&a->lease_list); if (a->dhcp_free_cb) a->dhcp_free_cb(a); @@ -323,6 +320,19 @@ inline static void free_assignment(struct dhcp_assignment *a) free(a); } +inline static struct dhcp_assignment *alloc_assignment(size_t extra_len) +{ + struct dhcp_assignment *a = calloc(1, sizeof(*a) + extra_len); + + if (!a) + return NULL; + + INIT_LIST_HEAD(&a->head); + INIT_LIST_HEAD(&a->lease_list); + + return a; +} + // Exported main functions int odhcpd_register(struct odhcpd_event *event); int odhcpd_deregister(struct odhcpd_event *event); |