On Thu, Feb 25, 2016 at 11:11:45AM +0200, Amir Vadai" wrote: > Hi, > > I have a kernel patch that I would like to post upstream. I get a memory leak > warning on it, it is a false positive. See below for a simplified example: > > When runing: > $ ~/git/smatch/smatch_scripts/kchecker smatch_test.c > > I get this: > > smatch_test.c:11 test() warn: possible memory leak of 'a' > CC smatch_test.o > > > On the below trival code: > > #include <linux/slab.h> > > int test(void) > { > void *a = kmalloc(1000, GFP_KERNEL); > bool f = false; > > if (!f) > kfree(a); This is like what Oleg was asking about last week. We know that this condition is true and actually Smatch knows this condition is true as well. But it is a tricky question of how to handle these things where we know the condition is true. It's tricky from a philosophical point of view as well as an implementation point of view. Why do we have this known condition true? Wouldn't it be cleaner to just remove it? > > return 0; > } Also you have to be really careful when writing test cases. How sure are you that "bool" and "false" are defined? Smatch won't complain about it, but can lead to wierd results. Can you send the patch itself? regards, dan carpenter -- To unsubscribe from this list: send the line "unsubscribe smatch" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html