facebook / facebook/infer

False positive: memory pointer stored in structures incorrectly marked as leaking

Ouverte
#743 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub
false-positive
Langage dominant
OCaml
Étoiles
15.7k
Forks
2.1k
Merge moyen
19 h 36 min
PR mergées (30 j)
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
```

Guide de contribution

Ouvrir le guide de contribution

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.