[c] record complex sizeof() and leak from #86

Summary:
Infer does the right thing now, make sure it doesn't regress.
https://github.com/facebook/infer/issues/86

Reviewed By: mbouaziz, dulmarod

Differential Revision: D8442855

fbshipit-source-id: 3df29b88c
master
Jules Villard 7 years ago committed by Facebook Github Bot
parent d86737946c
commit 6e44cae7cd

@ -60,3 +60,24 @@ void call_two_loops_Bad() {
int m = 15;
a[two_loops(m)] = 1;
}
struct payload {
int count;
int payload[];
};
#define COUNT 10
// memleak but no array out of bounds error
void malloc_sizeof_value_leak_good() {
struct payload* x;
x = malloc(sizeof(*x) + COUNT * sizeof(x->payload[0]));
if (x == NULL) {
return 1;
}
x->count = COUNT;
for (int i = 0; i < COUNT; i++) {
x->payload[i] = i;
}
/* missing free(x) */
}

@ -32,6 +32,8 @@ codetoanalyze/c/errors/memory_leaks/cleanup_attribute.c, FP_cleanup_string_good,
codetoanalyze/c/errors/memory_leaks/test.c, common_realloc_leak, 3, MEMORY_LEAK, no_bucket
codetoanalyze/c/errors/memory_leaks/test.c, common_realloc_leak, 5, NULL_TEST_AFTER_DEREFERENCE, no_bucket
codetoanalyze/c/errors/memory_leaks/test.c, conditional_last_instruction, 2, MEMORY_LEAK, no_bucket
codetoanalyze/c/errors/memory_leaks/test.c, malloc_sizeof_value_leak_bad, 7, MEMORY_LEAK, no_bucket
codetoanalyze/c/errors/memory_leaks/test.c, malloc_sizeof_value_leak_bad, 8, ARRAY_OUT_OF_BOUNDS_L3, no_bucket
codetoanalyze/c/errors/memory_leaks/test.c, simple_leak, 2, MEMORY_LEAK, no_bucket
codetoanalyze/c/errors/memory_leaks/test.c, uses_allocator, 3, MEMORY_LEAK, no_bucket
codetoanalyze/c/errors/mutex/pthread_mutex.c, double_init_bad, 2, PRECONDITION_NOT_MET, no_bucket

@ -57,3 +57,23 @@ int* compound_return_no_leak() {
p;
});
}
struct payload {
int count;
int payload[];
};
#define COUNT 10
void malloc_sizeof_value_leak_bad() {
struct payload* x;
x = malloc(sizeof(*x) + COUNT * sizeof(x->payload[0]));
if (x == NULL) {
return 1;
}
x->count = COUNT;
for (int i = 0; i < COUNT; i++) {
x->payload[i] = i;
}
/* missing free(x) */
}

Loading…
Cancel
Save