False positive: memory pointer stored in structures incorrectly marked as leaking
- Dominant language
- OCaml
- Stars
- 15.7k
- Forks
- 2.1k
- Avg merge
- 19h 36m
- Merged PRs (30d)
- 13
Description
A function allocates memory and stores the pointer in structure, which is then returned from the function. The memory allocated is incorrectly inferred to be unreachable after function exit.
This issue may be connected to that reported in [#704]
Minimal example below. Infer run from a vanilla docker image created as instructions on http://fbinfer.com/docs/getting-started.html
```C
#include
struct retval {
int i;
float * f;
};
struct retval make_struct(size_t n){
float * f = calloc(n, sizeof(float));
struct retval ret = {0, f};
return ret;
}
int main(void){
struct retval ret = make_struct(5);
free(ret.f);
return EXIT_SUCCESS;
}
```
```
# infer --version
Infer version v0.12.1
Copyright 2009 - present Facebook. All Rights Reserved.
# infer -- clang -c structure_leak.c
Capturing in make/cc mode...
Found 1 source file to analyze in /opt/android-sdk-linux/scrappie/infer-out
Starting analysis...
legend:
"F" analyzing a file
"." analyzing a procedure
F..
Found 1 issue
structure_leak.c:12: error: MEMORY_LEAK
memory dynamically allocated to `ret.f` by call to `calloc()` at line 9, column 17 is not reachable after line 12, column 5
10. struct retval ret = {0, f};
11.
12. > return ret;
13. }
14.
Summary of the reports
MEMORY_LEAK: 1
```
Contributor guide
Assessment
This issue has not been assessed yet.