Skip to content

Commit

Permalink
tools/nut-scanner/scan_snmp.c, scripts/valgrind/.valgrind.supp: const…
Browse files Browse the repository at this point in the history
…rain libnetsnmp leak reports [networkupstools#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 <[email protected]>
  • Loading branch information
jimklimov committed Jul 10, 2024
1 parent e820654 commit 28343c9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
7 changes: 7 additions & 0 deletions scripts/valgrind/.valgrind.supp
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,10 @@
fun:_dlerror_run
...
}
{
<nut-scanner-snmp-libinit>
Memcheck:Leak
...
fun:init_snmp_once
...
}
15 changes: 10 additions & 5 deletions tools/nut-scanner/scan_snmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 28343c9

Please sign in to comment.