config: use free_lease to delete a lease
authorHans Dedecker <dedeckeh@gmail.com>
Thu, 29 Dec 2016 14:17:13 +0000 (15:17 +0100)
committerHans Dedecker <dedeckeh@gmail.com>
Thu, 29 Dec 2016 14:28:57 +0000 (15:28 +0100)
Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
src/config.c

index daf583b5e2bbda7fa045ae9c6e8c658354c36b4c..e3bf78a96d55e7879fbf9b639eea3bebad2e9868 100644 (file)
@@ -162,6 +162,15 @@ static int mkdir_p(char *dir, mode_t mask)
        return ret;
 }
 
+static void free_lease(struct lease *l)
+{
+       if (l->head.next)
+               list_del(&l->head);
+
+       free(l->duid);
+       free(l);
+}
+
 static struct interface* get_interface(const char *name)
 {
        struct interface *c;
@@ -323,10 +332,9 @@ static int set_lease(struct uci_section *s)
        return 0;
 
 err:
-       if (lease) {
-               free(lease->duid);
-               free(lease);
-       }
+       if (lease)
+               free_lease(lease);
+
        return -1;
 }
 
@@ -607,12 +615,8 @@ void odhcpd_reload(void)
 {
        struct uci_context *uci = uci_alloc_context();
 
-       while (!list_empty(&leases)) {
-               struct lease *l = list_first_entry(&leases, struct lease, head);
-               list_del(&l->head);
-               free(l->duid);
-               free(l);
-       }
+       while (!list_empty(&leases))
+               free_lease(list_first_entry(&leases, struct lease, head));
 
        struct interface *master = NULL, *i, *n;