From 28343c9468d7ad3a029e6f92c3aea9c9307c10ca Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Wed, 10 Jul 2024 22:06:45 +0200 Subject: [PATCH] tools/nut-scanner/scan_snmp.c, scripts/valgrind/.valgrind.supp: constrain libnetsnmp leak reports [#2511] It seems that although `init_snmp()` is called once, every use of the library initializes some data which it then does not release, at least on the test system here. Signed-off-by: Jim Klimov --- scripts/valgrind/.valgrind.supp | 7 +++++++ tools/nut-scanner/scan_snmp.c | 15 ++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/scripts/valgrind/.valgrind.supp b/scripts/valgrind/.valgrind.supp index fb75ef2ea6..c92a80bb48 100644 --- a/scripts/valgrind/.valgrind.supp +++ b/scripts/valgrind/.valgrind.supp @@ -94,3 +94,10 @@ fun:_dlerror_run ... } +{ + + Memcheck:Leak + ... + fun:init_snmp_once + ... +} diff --git a/tools/nut-scanner/scan_snmp.c b/tools/nut-scanner/scan_snmp.c index 02b1c85298..18f3e559ab 100644 --- a/tools/nut-scanner/scan_snmp.c +++ b/tools/nut-scanner/scan_snmp.c @@ -1057,6 +1057,15 @@ static void * try_SysOID_thready(void * arg) return NULL; } +static void init_snmp_once(void) +{ + /* Initialize the SNMP library */ + if (!nut_initialized_snmp) { + (*nut_init_snmp)("nut-scanner"); + nut_initialized_snmp = 1; + } +} + nutscan_device_t * nutscan_scan_snmp(const char * start_ip, const char * stop_ip, useconds_t usec_timeout, nutscan_snmp_t * sec) { @@ -1166,11 +1175,7 @@ nutscan_device_t * nutscan_scan_ip_range_snmp(nutscan_ip_range_list_t * irl, upsdebugx(1, "Failed to enable numeric OIDs resolution"); } - /* Initialize the SNMP library */ - if (!nut_initialized_snmp) { - (*nut_init_snmp)("nut-scanner"); - nut_initialized_snmp = 1; - } + init_snmp_once(); ip_str = nutscan_ip_ranges_iter_init(&ip, irl);