|
|
c1154d |
From 8bb544fbd2d6986a9b73d3fab49235a4baa96c23 Mon Sep 17 00:00:00 2001
|
|
|
c1154d |
From: Bart Van Assche <bvanassche@acm.org>
|
|
|
c1154d |
Date: Sat, 31 Jul 2021 16:21:16 -0700
|
|
|
c1154d |
Subject: [PATCH] Linux: IF-MIB: Fix a memory leak
|
|
|
c1154d |
|
|
|
c1154d |
The Linux kernel regenerates proc files in their entirety every time a 4 KiB
|
|
|
c1154d |
boundary is crossed. This can result in reading the same network interface
|
|
|
c1154d |
twice if network information changes while it is being read. Fix a memory
|
|
|
c1154d |
leak that can be triggered if /proc/net/dev changes while being read.
|
|
|
c1154d |
---
|
|
|
c1154d |
agent/mibgroup/if-mib/data_access/interface_linux.c | 10 +++++++++-
|
|
|
c1154d |
1 file changed, 9 insertions(+), 1 deletion(-)
|
|
|
c1154d |
|
|
|
c1154d |
diff --git a/agent/mibgroup/if-mib/data_access/interface_linux.c b/agent/mibgroup/if-mib/data_access/interface_linux.c
|
|
|
c1154d |
index e99360a216..215b30e806 100644
|
|
|
c1154d |
--- a/agent/mibgroup/if-mib/data_access/interface_linux.c
|
|
|
c1154d |
+++ b/agent/mibgroup/if-mib/data_access/interface_linux.c
|
|
|
c1154d |
@@ -921,7 +921,15 @@ netsnmp_arch_interface_container_load(netsnmp_container* container,
|
|
|
c1154d |
/*
|
|
|
c1154d |
* add to container
|
|
|
c1154d |
*/
|
|
|
c1154d |
- CONTAINER_INSERT(container, entry);
|
|
|
c1154d |
+ if (CONTAINER_INSERT(container, entry) != 0) {
|
|
|
c1154d |
+ netsnmp_interface_entry *existing =
|
|
|
c1154d |
+ CONTAINER_FIND(container, entry);
|
|
|
c1154d |
+ NETSNMP_LOGONCE((LOG_WARNING,
|
|
|
c1154d |
+ "Encountered interface with index %" NETSNMP_PRIz "u twice: %s <> %s",
|
|
|
c1154d |
+ entry->index, existing ? existing->name : "(?)",
|
|
|
c1154d |
+ entry->name));
|
|
|
c1154d |
+ netsnmp_access_interface_entry_free(entry);
|
|
|
c1154d |
+ }
|
|
|
c1154d |
}
|
|
|
c1154d |
#ifdef NETSNMP_ENABLE_IPV6
|
|
|
c1154d |
netsnmp_access_ipaddress_container_free(addr_container, 0);
|
|
|
c1154d |
|