From ed87ed048a81ae8f6e4d23a583f7fcffb1463fe5 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Wed, 10 Jul 2024 22:24:49 +0200 Subject: [PATCH] tools/nut-scanner/scan_ipmi.c, tools/nut-scanner/scan_avahi.c, scripts/valgrind/.valgrind.supp: constrain warnings about library methods [#2511] Signed-off-by: Jim Klimov --- scripts/valgrind/.valgrind.supp | 14 ++++++++++++++ tools/nut-scanner/scan_avahi.c | 7 ++++++- tools/nut-scanner/scan_ipmi.c | 7 ++++++- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/scripts/valgrind/.valgrind.supp b/scripts/valgrind/.valgrind.supp index c92a80bb48..8cacb8f338 100644 --- a/scripts/valgrind/.valgrind.supp +++ b/scripts/valgrind/.valgrind.supp @@ -101,3 +101,17 @@ fun:init_snmp_once ... } +{ + + Memcheck:Leak + ... + fun:wrap_nut_ipmi_ctx_create + ... +} +{ + + Memcheck:Leak + ... + fun:wrap_nut_avahi_client_new + ... +} diff --git a/tools/nut-scanner/scan_avahi.c b/tools/nut-scanner/scan_avahi.c index d83174167f..a6ce9d6c99 100644 --- a/tools/nut-scanner/scan_avahi.c +++ b/tools/nut-scanner/scan_avahi.c @@ -530,6 +530,11 @@ static void client_callback(AvahiClient *c, AvahiClientState state, void * userd } } +static AvahiClient* wrap_nut_avahi_client_new(int *error) +{ + return (*nut_avahi_client_new)((*nut_avahi_simple_poll_get)(simple_poll), 0, client_callback, NULL, error); +} + nutscan_device_t * nutscan_scan_avahi(useconds_t usec_timeout) { /* Example service publication @@ -561,7 +566,7 @@ nutscan_device_t * nutscan_scan_avahi(useconds_t usec_timeout) * but lacks a value in that enum for lack of flags (unconstrained * lookup). So we have to silence a warning here... */ - client = (*nut_avahi_client_new)((*nut_avahi_simple_poll_get)(simple_poll), 0, client_callback, NULL, &error); + client = wrap_nut_avahi_client_new(&error); #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_ASSIGN_ENUM) # pragma GCC diagnostic pop #endif diff --git a/tools/nut-scanner/scan_ipmi.c b/tools/nut-scanner/scan_ipmi.c index ad4820a56f..44f4fd3325 100644 --- a/tools/nut-scanner/scan_ipmi.c +++ b/tools/nut-scanner/scan_ipmi.c @@ -421,6 +421,11 @@ static int is_ipmi_device_supported(ipmi_ctx_t ipmi_ctx, int ipmi_id) return 0; } +static ipmi_ctx_t wrap_nut_ipmi_ctx_create(void) +{ + return (*nut_ipmi_ctx_create) (); +} + /* Check for IPMI support on a specific (local or remote) system * Return NULL on error, or a valid nutscan_device_t otherwise */ nutscan_device_t * nutscan_scan_ipmi_device(const char * IPaddr, nutscan_ipmi_t * ipmi_sec) @@ -437,7 +442,7 @@ nutscan_device_t * nutscan_scan_ipmi_device(const char * IPaddr, nutscan_ipmi_t } /* Initialize the FreeIPMI library. */ - if (!(ipmi_ctx = (*nut_ipmi_ctx_create) ())) + if (!(ipmi_ctx = wrap_nut_ipmi_ctx_create())) { /* we have to force cleanup, since exit handler is not yet installed */ fprintf(stderr, "Failed to ipmi_ctx_create\n");