You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
2.5 KiB

  1. From 7cc9f2c7953d48cfb70b7e0c1b0c57e45ae68ce8 Mon Sep 17 00:00:00 2001
  2. From: Stephen Worley <sworley@cumulusnetworks.com>
  3. Date: Wed, 1 Apr 2020 15:31:40 -0400
  4. Subject: [PATCH] zebra: free unhashable (dup) NHEs via ID table cleanup
  5. Free unhashable (duplicate NHEs from the kernel) via ID table
  6. cleanup. Since the NHE ID hash table contains extra entries,
  7. that's the one we need to be calling zebra_nhg_hash_free()
  8. on, otherwise we will never free the unhashable NHEs.
  9. This was found via a memleak:
  10. ==1478713== HEAP SUMMARY:
  11. ==1478713== in use at exit: 10,267 bytes in 46 blocks
  12. ==1478713== total heap usage: 76,810 allocs, 76,764 frees, 3,901,237 bytes allocated
  13. ==1478713==
  14. ==1478713== 208 (88 direct, 120 indirect) bytes in 1 blocks are definitely lost in loss record 35 of 41
  15. ==1478713== at 0x483BB1A: calloc (vg_replace_malloc.c:762)
  16. ==1478713== by 0x48E35E8: qcalloc (memory.c:110)
  17. ==1478713== by 0x451CCB: zebra_nhg_alloc (zebra_nhg.c:369)
  18. ==1478713== by 0x453DE3: zebra_nhg_copy (zebra_nhg.c:379)
  19. ==1478713== by 0x452670: nhg_ctx_process_new (zebra_nhg.c:1143)
  20. ==1478713== by 0x4523A8: nhg_ctx_process (zebra_nhg.c:1234)
  21. ==1478713== by 0x452A2D: zebra_nhg_kernel_find (zebra_nhg.c:1294)
  22. ==1478713== by 0x4326E0: netlink_nexthop_change (rt_netlink.c:2433)
  23. ==1478713== by 0x427320: netlink_parse_info (kernel_netlink.c:945)
  24. ==1478713== by 0x432DAD: netlink_nexthop_read (rt_netlink.c:2488)
  25. ==1478713== by 0x41B600: interface_list (if_netlink.c:1486)
  26. ==1478713== by 0x457275: zebra_ns_enable (zebra_ns.c:127)
  27. Repro with:
  28. ip next add id 1 blackhole
  29. ip next add id 2 blackhole
  30. valgrind /usr/lib/frr/zebra
  31. Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
  32. (cherry picked from commit c25c3ea57a3dcd3b36d86ba76dd34961bcb662f0)
  33. ---
  34. zebra/zebra_router.c | 7 ++++---
  35. 1 file changed, 4 insertions(+), 3 deletions(-)
  36. diff --git a/zebra/zebra_router.c b/zebra/zebra_router.c
  37. index a891ffb76a..ea2b6752b3 100644
  38. --- a/zebra/zebra_router.c
  39. +++ b/zebra/zebra_router.c
  40. @@ -223,10 +223,11 @@ void zebra_router_terminate(void)
  41. zebra_vxlan_disable();
  42. zebra_mlag_terminate();
  43. - hash_clean(zrouter.nhgs, zebra_nhg_hash_free);
  44. - hash_free(zrouter.nhgs);
  45. - hash_clean(zrouter.nhgs_id, NULL);
  46. + /* Free NHE in ID table only since it has unhashable entries as well */
  47. + hash_clean(zrouter.nhgs_id, zebra_nhg_hash_free);
  48. hash_free(zrouter.nhgs_id);
  49. + hash_clean(zrouter.nhgs, NULL);
  50. + hash_free(zrouter.nhgs);
  51. hash_clean(zrouter.rules_hash, zebra_pbr_rules_free);
  52. hash_free(zrouter.rules_hash);