From 87f484516d951f080efb9d523ee289fd360fe0c8 Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Fri, 18 Mar 2016 15:05:40 +0100 Subject: [PATCH] lldpcli: silence expected memory leaks The suppression file doesn't have the same syntax as valgrind. Instead, use code annotations. --- src/client/client.h | 12 ++++++++++++ src/client/conf-lldp.c | 1 + src/client/conf-med.c | 13 +++++++++---- src/client/conf-power.c | 4 +++- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/client/client.h b/src/client/client.h index 62174b3c..6563346a 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -29,6 +29,18 @@ #include "../compat/compat.h" #include "writer.h" +#if defined(__has_feature) +# if __has_feature(address_sanitizer) +# define __SANITIZE_ADDRESS__ +# endif +#endif +#ifdef __SANITIZE_ADDRESS__ +# include +# define SUPPRESS_LEAK(x) __lsan_ignore_object(x) +#else +# define SUPPRESS_LEAK(x) +#endif + /* Readline stuff */ #ifdef HAVE_LIBREADLINE # if defined(HAVE_READLINE_READLINE_H) diff --git a/src/client/conf-lldp.c b/src/client/conf-lldp.c index 4998008c..b8a5a130 100644 --- a/src/client/conf-lldp.c +++ b/src/client/conf-lldp.c @@ -476,6 +476,7 @@ register_commands_configure_lldp(struct cmd_node *configure, status_map->string; status_map++) { const char *tag = strdup(totag(status_map->string)); + SUPPRESS_LEAK(tag); commands_new( commands_new(status, tag, diff --git a/src/client/conf-med.c b/src/client/conf-med.c index 226b3d82..180272a8 100644 --- a/src/client/conf-med.c +++ b/src/client/conf-med.c @@ -318,15 +318,18 @@ register_commands_medloc_addr(struct cmd_node *configure_medlocation) for (lldpctl_map_t *addr_map = lldpctl_key_get_map(lldpctl_k_med_civicaddress_type); addr_map->string; - addr_map++) + addr_map++) { + const char *tag = strdup(totag(addr_map->string)); + SUPPRESS_LEAK(tag); commands_new( commands_new( configure_medloc_addr, - strdup(totag(addr_map->string)), /* TODO: memory leak, happens once */ + tag, addr_map->string, cmd_check_no_env, NULL, addr_map->string), NULL, addr_map->string, NULL, cmd_store_env_value_and_pop2, addr_map->string); + } } /** @@ -412,7 +415,8 @@ register_commands_medpol(struct cmd_node *configure_med) lldpctl_key_get_map(lldpctl_k_med_policy_type); pol_map->string; pol_map++) { - char *tag = strdup(totag(pol_map->string)); /* TODO: memory leak, happens once */ + char *tag = strdup(totag(pol_map->string)); + SUPPRESS_LEAK(tag); commands_new( configure_application, tag, @@ -452,7 +456,8 @@ register_commands_medpol(struct cmd_node *configure_med) lldpctl_key_get_map(lldpctl_k_med_policy_priority); prio_map->string; prio_map++) { - char *tag = strdup(totag(prio_map->string)); /* TODO: memory leak, happens once */ + char *tag = strdup(totag(prio_map->string)); + SUPPRESS_LEAK(tag); commands_new( priority, tag, prio_map->string, diff --git a/src/client/conf-power.c b/src/client/conf-power.c index 79bddb51..ef6f9ccd 100644 --- a/src/client/conf-power.c +++ b/src/client/conf-power.c @@ -242,7 +242,8 @@ register_commands_pow_priority(struct cmd_node *priority, int key) lldpctl_key_get_map(key); prio_map->string; prio_map++) { - char *tag = strdup(totag(prio_map->string)); /* TODO: memory leak, happens once */ + char *tag = strdup(totag(prio_map->string)); + SUPPRESS_LEAK(tag); commands_new( priority, tag, @@ -382,6 +383,7 @@ register_commands_dot3pow(struct cmd_node *configure_dot3) class_map->string; class_map++) { const char *tag = strdup(totag(class_map->string)); + SUPPRESS_LEAK(tag); commands_new( class, tag, -- 2.39.5