[ovs-dev] [PATCH 4/4] util: Fix potential leak of memory.

William Tu u9012063 at gmail.com
Mon Oct 30 17:27:55 UTC 2017


Clang reports potiential leak of memory pointed to by 'pname'.
We already free the previous subporgram name when setting the
new subprogram name, and once the running thread exits, the
name of the process will be free by the system.  Thus, we don't
need to explicitly free it, so exclude the clang analyzer as a
workaround.

Signed-off-by: William Tu <u9012063 at gmail.com>
---
 lib/util.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lib/util.c b/lib/util.c
index a26cd51dcf6d..7153e8b8a5b6 100644
--- a/lib/util.c
+++ b/lib/util.c
@@ -534,6 +534,7 @@ get_subprogram_name(void)
 void
 set_subprogram_name(const char *subprogram_name)
 {
+#ifndef __clang_analyzer__
     char *pname = xstrdup(subprogram_name ? subprogram_name : program_name);
     free(subprogram_name_set(pname));
 
@@ -544,6 +545,7 @@ set_subprogram_name(const char *subprogram_name)
 #elif HAVE_PTHREAD_SET_NAME_NP
     pthread_set_name_np(pthread_self(), pname);
 #endif
+#endif
 }
 
 unsigned int
-- 
2.7.4



More information about the dev mailing list