diff mbox series

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

Message ID 1509384475-27951-5-git-send-email-u9012063@gmail.com
State Rejected
Headers show
Series Fix clang static checker errors. | expand

Commit Message

William Tu Oct. 30, 2017, 5:27 p.m. UTC
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@gmail.com>
---
 lib/util.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Ben Pfaff Oct. 30, 2017, 7:49 p.m. UTC | #1
On Mon, Oct 30, 2017 at 10:27:55AM -0700, William Tu wrote:
> 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@gmail.com>

Thanks for reporting this.

I don't think it's worthwhile adding an #if to satisfy clang-analyzer
here.  I don't think it should be our goal to make clang-analyzer
produce no output; it does not have enough context to understand
everything that OVS does.
William Tu Oct. 30, 2017, 7:55 p.m. UTC | #2
On Mon, Oct 30, 2017 at 12:49 PM, Ben Pfaff <blp@ovn.org> wrote:
> On Mon, Oct 30, 2017 at 10:27:55AM -0700, William Tu wrote:
>> 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@gmail.com>
>
> Thanks for reporting this.
>
> I don't think it's worthwhile adding an #if to satisfy clang-analyzer
> here.  I don't think it should be our goal to make clang-analyzer
> produce no output; it does not have enough context to understand
> everything that OVS does.

Hi Ben,
Thanks for the review. Yes, I agree clang-analyzer in many cases
doesn't have enough context. I will leave these warnings there.
William
diff mbox series

Patch

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