]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
lldpcli: silence expected memory leaks
authorVincent Bernat <vincent@bernat.im>
Fri, 18 Mar 2016 14:05:40 +0000 (15:05 +0100)
committerVincent Bernat <vincent@bernat.im>
Fri, 18 Mar 2016 18:34:54 +0000 (19:34 +0100)
The suppression file doesn't have the same syntax as valgrind. Instead,
use code annotations.

src/client/client.h
src/client/conf-lldp.c
src/client/conf-med.c
src/client/conf-power.c

index 62174b3c9a61ec28028abbb01e9bb2771a4875de..6563346af37932ee745396c22cd0250b6f5f4db7 100644 (file)
 #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 <sanitizer/lsan_interface.h>
+# 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)
index 4998008c075f1f2bcc86e638bdff9a12bb8ec2f6..b8a5a130b1ed05d1e727ba202a947b166e36d0ee 100644 (file)
@@ -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,
index 226b3d82c700f57089b7c2ce09f64cd5c41c27de..180272a88ae0da212f2073800cc32f9f63c56835 100644 (file)
@@ -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,
index 79bddb515e3c8fd55d959e7c7cd6bd3cfdf23f32..ef6f9ccd1c55687e63a0f030c8b06370bef54804 100644 (file)
@@ -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,