]> git.puffer.fish Git - matthieu/frr.git/commitdiff
isisd: Fix memory leak in copy_tlv_router_cap
authorDonald Sharp <sharpd@nvidia.com>
Tue, 27 Oct 2020 16:40:46 +0000 (12:40 -0400)
committerIgor Ryzhov <iryzhov@nfware.com>
Wed, 28 Oct 2020 18:35:48 +0000 (21:35 +0300)
There exists a code path where we would allocate memory
then test a variable and then immediately return NULL.
Prevent memory from leaking in this situation.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
isisd/isis_tlvs.c

index a1f9cc236ff75d4df146c99dca7d822410a7d333..ea429561e2920ca2a600bdaa9e3c040ffd016f6c 100644 (file)
@@ -2400,11 +2400,11 @@ static int unpack_tlv_threeway_adj(enum isis_tlv_context context,
 }
 
 /* Functions related to TLVs 236/237 IPv6/MT-IPv6 reach */
-
 static struct isis_item *copy_item_ipv6_reach(struct isis_item *i)
 {
        struct isis_ipv6_reach *r = (struct isis_ipv6_reach *)i;
        struct isis_ipv6_reach *rv = XCALLOC(MTYPE_ISIS_TLV, sizeof(*rv));
+
        rv->metric = r->metric;
        rv->down = r->down;
        rv->external = r->external;
@@ -2573,11 +2573,13 @@ out:
 static struct isis_router_cap *copy_tlv_router_cap(
                               const struct isis_router_cap *router_cap)
 {
-       struct isis_router_cap *rv = XMALLOC(MTYPE_ISIS_TLV, sizeof(*rv));
+       struct isis_router_cap *rv;
 
        if (!router_cap)
                return NULL;
 
+       rv = XMALLOC(MTYPE_ISIS_TLV, sizeof(*rv));
+
        memcpy(rv, router_cap, sizeof(*rv));
 
        return rv;