]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Rework arp_free and arp_free_but to share a common function.
authorRoy Marples <roy@marples.name>
Tue, 8 Sep 2015 12:23:19 +0000 (12:23 +0000)
committerRoy Marples <roy@marples.name>
Tue, 8 Sep 2015 12:23:19 +0000 (12:23 +0000)
Less code and works around a clang static analyzer bug.

arp.c

diff --git a/arp.c b/arp.c
index 9f6b00dfe69cc623a531f11c502224a772b3e1d3..b45201f1a7fafe9b5003f227c1a1bd771378e332 100644 (file)
--- a/arp.c
+++ b/arp.c
@@ -379,33 +379,33 @@ arp_free(struct arp_state *astate)
        }
 }
 
-void
-arp_free_but(struct arp_state *astate)
+static void
+arp_free_but1(struct interface *ifp, struct arp_state *astate)
 {
        struct iarp_state *state;
-       struct arp_state *p, *n;
 
-       state = ARP_STATE(astate->iface);
-       TAILQ_FOREACH_SAFE(p, &state->arp_states, next, n) {
-               if (p != astate)
-                       arp_free(p);
+       if ((state = ARP_STATE(ifp)) != NULL) {
+               struct arp_state *p, *n;
+
+               TAILQ_FOREACH_SAFE(p, &state->arp_states, next, n) {
+                       if (p != astate)
+                               arp_free(p);
+               }
        }
 }
 
+void
+arp_free_but(struct arp_state *astate)
+{
+
+       arp_free_but1(astate->iface, astate);
+}
+
 void
 arp_close(struct interface *ifp)
 {
-       struct iarp_state *state;
-       struct arp_state *astate;
 
-       /* Freeing the last state will also free the main state,
-        * so test for both. */
-       for (;;) {
-               if ((state = ARP_STATE(ifp)) == NULL ||
-                   (astate = TAILQ_FIRST(&state->arp_states)) == NULL)
-                       break;
-               arp_free(astate);
-       }
+       arp_free_but1(ifp, NULL);
 }
 
 void