NoQ added inline comments.

================
Comment at: clang/test/Analysis/malloc-static-storage.cpp:33-38
+void malloc_escape() {
+  static int *p;
+  p = (int *)malloc(sizeof(int));
+  escape(p); // no-leak
+  p = 0; // no-leak
+}
----------------
NoQ wrote:
> NoQ wrote:
> > The main problem with static locals is that this can happen the other way 
> > round:
> > 
> > ```lang=c
> > void malloc_escape() {
> >   static int *p;
> >   escape(p);
> >   p = (int *)malloc(sizeof(int));
> >   p = 0; // no-leak
> > }
> > ```
> Wait, I misread. I'm thinking of a situation like this:
> ```
> void malloc_escape() {
>   static int *p;
>   escape(&p); // added '&'
>   p = (int *)malloc(sizeof(int));
>   p = 0; // no-leak
> }
> ```
Technically this is also a problem with non-static locals if we complicate the 
situation a little bit:

```lang=c
void malloc_escape() {
  int *p;
  escape(&p);
  p = (int *)malloc(sizeof(int));
  free_whatever_escaped();
  p = 0; // currently false leak warning
}
```

We've had a lovely conversation about this with @xazax.hun in D71041 and D71224 
but we've failed to produce a good solution back then.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139534/new/

https://reviews.llvm.org/D139534

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to