netlink: make it clearer that we're handling realloc correctly
authorDavid Härdeman <[email protected]>
Sun, 23 Nov 2025 14:15:33 +0000 (15:15 +0100)
committerÁlvaro Fernández Rojas <[email protected]>
Thu, 27 Nov 2025 07:24:53 +0000 (08:24 +0100)
This doesn't really change the code, it just makes it clearer when
grepping for realloc() that failure is handled correctly.

Signed-off-by: David Härdeman <[email protected]>
Link: https://github.com/openwrt/odhcpd/pull/320
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
src/netlink.c

index c07a9e4bea33435f6279213762b292ce3fa3f131..d58e45273ef7f761f828f220efadeff6e5949cd4 100644 (file)
@@ -531,7 +531,7 @@ struct addr_info {
 static int cb_addr_valid(struct nl_msg *msg, void *arg)
 {
        struct addr_info *ctxt = (struct addr_info *)arg;
-       struct odhcpd_ipaddr *oaddrs = *(ctxt->oaddrs);
+       struct odhcpd_ipaddr *oaddrs;
        struct nlmsghdr *hdr = nlmsg_hdr(msg);
        struct ifaddrmsg *ifa;
        struct nlattr *nla[__IFA_MAX], *nla_addr = NULL;
@@ -564,7 +564,7 @@ static int cb_addr_valid(struct nl_msg *msg, void *arg)
        if (!nla_addr)
                return NL_SKIP;
 
-       oaddrs = realloc(oaddrs, sizeof(*oaddrs) * (ctxt->ret + 1));
+       oaddrs = realloc(*(ctxt->oaddrs), sizeof(*oaddrs) * (ctxt->ret + 1));
        if (!oaddrs)
                return NL_SKIP;
 
@@ -721,7 +721,7 @@ out:
 static int cb_linklocal_valid(struct nl_msg *msg, void *arg)
 {
        struct addr_info *ctxt = (struct addr_info *)arg;
-       struct odhcpd_ipaddr *oaddrs = *(ctxt->oaddrs);
+       struct odhcpd_ipaddr *oaddrs;
        struct nlmsghdr *hdr = nlmsg_hdr(msg);
        struct ifaddrmsg *ifa;
        struct nlattr *nla[__IFA_MAX], *nla_addr = NULL;
@@ -755,7 +755,7 @@ static int cb_linklocal_valid(struct nl_msg *msg, void *arg)
        if (!IN6_IS_ADDR_LINKLOCAL(&addr))
                return NL_SKIP;
 
-       oaddrs = realloc(oaddrs, sizeof(*oaddrs) * (ctxt->ret + 1));
+       oaddrs = realloc(*(ctxt->oaddrs), sizeof(*oaddrs) * (ctxt->ret + 1));
        if (!oaddrs)
                return NL_SKIP;