| Issue |
182958
|
| Summary |
clang-analyzer-unix.Malloc memory released false positive with defer
|
| Labels |
false-positive
|
| Assignees |
|
| Reporter |
agl-alexglopez
|
In this C program, the clang analyzer believes memory is released at the use of `defer`. This is similar to issue #175639. However, the specific warning, and use of `defer`, is different so I opened a new issue.
Clang compiler and tidy version.
```txt
clang version 22.1.0-rc3 (https://github.com/llvm/llvm-project 8530a2cf135c6091438b92b3778d1f23bf77d905)
Target: x86_64-unknown-linux-gnu
Thread model: posix
```
Program compiled with the `-fdefer-ts` flag.
```c
#include <stddefer.h>
#include <stdlib.h>
int
main(void) {
int *num = malloc(sizeof(int));
defer free(num);
*num = 1;
return 0;
}
```
Clang tidy output.
```txt
<source>:8:10: warning: Use of memory after it is released [clang-analyzer-unix.Malloc]
8 | *num = 1;
| ~~~~ ^
<source>:6:16: note: Memory is allocated
6 | int *num = malloc(sizeof(int));
| ^~~~~~~~~~~~~~~~~~~
<source>:7:11: note: Memory is released
7 | defer free(num);
| ^~~~~~~~~
<source>:8:10: note: Use of memory after it is released
8 | *num = 1;
| ~~~~ ^
```
See https://godbolt.org/z/Y8xE9xqY7
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs