[cfe-commits] unix.Malloc static checker improvement: memory.LeakPtrValChanged

Anna Zaks ganna at apple.com
Fri Feb 1 10:20:52 PST 2013


On Jan 31, 2013, at 7:20 PM, Branden Archer <b.m.archer4 at gmail.com> wrote:

> Oh, one other thing. I do not know who does the committing when the patch is approved. Should I prove a patch that has my commit message in it and username? Would either of you be pushing the change, or would I be pushing it?
> 

One of us will push this and mention that the patch is by you in the commit message. Please do send the commit message!

> Also, thanks for your comments and discussion on this patch, and for keeping with it for so long! I appreciate your feedback and the opportunity to learn some about the static analyzer of clang.
> 
> - Branden
> 
> On Thu, Jan 31, 2013 at 10:10 PM, Branden Archer <b.m.archer4 at gmail.com> wrote:
> Have you double checked that the tests did not generate the warnings before the patch?
> 
> When you mentioned this, I had a moment of doubt. I checked for compiler warnings and the 'make test' before I emailed my patches, and all came back clean. Just to be sure I updated my source and compiled again, all still clean. Did you see something in particular, or just wanted to make sure?
> 

What I meant is that the tests should not pass before the patch is applied. Then, after you apply the patch, the tests should start passing.

> 
> +void testPassConstPointerIndirectly() {
> +  struct HasPtr hp;
> +  hp.p = fopen("myfile.txt", "w");
> +  fputc(0, (FILE *)&hp);
> +  return; // expected-warning {{Opened file is never closed; potential resource leak}}
> +}
> 
> Heh. Did you really want this test case? It's not actually valid (&hp is a FILE**, not a FILE*):
> 
> I knew the test was not proper code, but it was the only way I could think of to pass a structure to a known library function that was known to not close a file. I replaced it in the attached patches with passing the HasPtr structure to a function that accepts it as a const parameter. I am not sure this still tests the same thing (as I do not fully appreciate how the analyzer knows that a function will not close the stream. I am hoping that if the parameter is passed as a const that it will assume this).
> 
> - Branden
> 
> 
> On Thu, Jan 31, 2013 at 8:26 PM, Jordan Rose <jordan_rose at apple.com> wrote:
> 
> On Jan 31, 2013, at 5:21 , Branden Archer <b.m.archer4 at gmail.com> wrote:
> 
>> Basically, you need to pass a pointer which we are tracking to a function call indirectly (ex: as a field in a struct..). You should pass it to a function which is known not to free memory or close stream. Finally, you leak that resource/pointer.
>> 
>> Previously, we would have a false negative - no leak would be reported. Now, we should be catching the leak.
>> 
>> Ah, got you. See the first attached patch for these added cases.
>> 
>> - Branden
> 
> 
> +void testPassConstPointerIndirectly() {
> +  struct HasPtr hp;
> +  hp.p = fopen("myfile.txt", "w");
> +  fputc(0, (FILE *)&hp);
> +  return; // expected-warning {{Opened file is never closed; potential resource leak}}
> +}
> 
> Heh. Did you really want this test case? It's not actually valid (&hp is a FILE**, not a FILE*):
> 
> 
> A few remaining comments for the MallocChecker patch:
> 
> +  if (ExplodedNode *N = C.generateSink()) {
> 
> Please use an early return here.
> 
> 
> +    int offsetBytes = Offset.getOffset()/C.getASTContext().getCharWidth();
> 
> Very nitpicky, but can you put spaces around the /?
> 
> 
> +       << ((abs(offsetBytes) > 1) ? "bytes" : "byte")
> 
> Perfect!
> 
> Jordan
> 
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130201/f7abfa15/attachment.html>


More information about the cfe-commits mailing list