]> git.puffer.fish Git - mirror/frr.git/commitdiff
zebra: Fix lost memory on lsp free
authorDonald Sharp <sharpd@nvidia.com>
Tue, 26 Jul 2022 11:53:48 +0000 (07:53 -0400)
committerDonald Sharp <sharpd@nvidia.com>
Tue, 26 Jul 2022 16:41:11 +0000 (12:41 -0400)
When cleaning up memory associated with a lsp the
nhlfe is lost in some cases.

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

index 8fe5dd9d278aaa945aba02c7829219522f03df68..41f85af635436ce7cb21b4f58cc78707f8bb0d8b 100644 (file)
@@ -1142,6 +1142,21 @@ static void lsp_check_free(struct hash *lsp_table, struct zebra_lsp **plsp)
                lsp_free(lsp_table, plsp);
 }
 
+static void lsp_free_nhlfe(struct zebra_lsp *lsp)
+{
+       struct zebra_nhlfe *nhlfe;
+
+       while ((nhlfe = nhlfe_list_first(&lsp->nhlfe_list))) {
+               nhlfe_list_del(&lsp->nhlfe_list, nhlfe);
+               nhlfe_free(nhlfe);
+       }
+
+       while ((nhlfe = nhlfe_list_first(&lsp->backup_nhlfe_list))) {
+               nhlfe_list_del(&lsp->backup_nhlfe_list, nhlfe);
+               nhlfe_free(nhlfe);
+       }
+}
+
 /*
  * Dtor for an LSP: remove from ile hash, release any internal allocations,
  * free LSP object.
@@ -1149,7 +1164,6 @@ static void lsp_check_free(struct hash *lsp_table, struct zebra_lsp **plsp)
 static void lsp_free(struct hash *lsp_table, struct zebra_lsp **plsp)
 {
        struct zebra_lsp *lsp;
-       struct zebra_nhlfe *nhlfe;
 
        if (plsp == NULL || *plsp == NULL)
                return;
@@ -1160,13 +1174,7 @@ static void lsp_free(struct hash *lsp_table, struct zebra_lsp **plsp)
                zlog_debug("Free LSP in-label %u flags 0x%x",
                           lsp->ile.in_label, lsp->flags);
 
-       /* Free nhlfes, if any. */
-       frr_each_safe(nhlfe_list, &lsp->nhlfe_list, nhlfe)
-               nhlfe_del(nhlfe);
-
-       /* Free backup nhlfes, if any. */
-       frr_each_safe(nhlfe_list, &lsp->backup_nhlfe_list, nhlfe)
-               nhlfe_del(nhlfe);
+       lsp_free_nhlfe(lsp);
 
        hash_release(lsp_table, &lsp->ile);
        XFREE(MTYPE_LSP, lsp);
@@ -3669,6 +3677,7 @@ int zebra_mpls_static_lsp_del(struct zebra_vrf *zvrf, mpls_label_t in_label,
         */
        if (nhlfe_list_first(&lsp->nhlfe_list) == NULL) {
                lsp = hash_release(slsp_table, &tmp_ile);
+               lsp_free_nhlfe(lsp);
                XFREE(MTYPE_LSP, lsp);
        }
 
@@ -4009,6 +4018,8 @@ static void lsp_table_free(void *p)
 {
        struct zebra_lsp *lsp = p;
 
+       lsp_free_nhlfe(lsp);
+
        XFREE(MTYPE_LSP, lsp);
 }