[c] add test for cleanup attribute

Summary: Record that it is not supported: https://github.com/facebook/infer/issues/8

Reviewed By: mbouaziz, dulmarod

Differential Revision: D8442762

fbshipit-source-id: fa271cb
master
Jules Villard 7 years ago committed by Facebook Github Bot
parent dd8b0bcd51
commit 25627fd4d9

@ -26,6 +26,8 @@ codetoanalyze/c/errors/local_vars/local_vars.c, m1, 6, DIVIDE_BY_ZERO, no_bucket
codetoanalyze/c/errors/local_vars/local_vars.c, m2, 9, DIVIDE_BY_ZERO, no_bucket codetoanalyze/c/errors/local_vars/local_vars.c, m2, 9, DIVIDE_BY_ZERO, no_bucket
codetoanalyze/c/errors/local_vars/local_vars.c, mm, 6, DIVIDE_BY_ZERO, no_bucket codetoanalyze/c/errors/local_vars/local_vars.c, mm, 6, DIVIDE_BY_ZERO, no_bucket
codetoanalyze/c/errors/local_vars/local_vars.c, t, 8, DIVIDE_BY_ZERO, no_bucket codetoanalyze/c/errors/local_vars/local_vars.c, t, 8, DIVIDE_BY_ZERO, no_bucket
codetoanalyze/c/errors/memory_leaks/cleanup_attribute.c, FP_cleanup_malloc_good, 4, MEMORY_LEAK, no_bucket
codetoanalyze/c/errors/memory_leaks/cleanup_attribute.c, FP_cleanup_string_good, 2, MEMORY_LEAK, no_bucket
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, 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, 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, conditional_last_instruction, 2, MEMORY_LEAK, no_bucket

@ -0,0 +1,29 @@
/*
* Copyright (c) 2018-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include <stdlib.h>
#include <string.h>
void cleanup_char(char** x) { free(*x); }
void cleanup_int(int** x) { free(*x); }
// related to https://github.com/facebook/infer/issues/8
void FP_cleanup_malloc_good() {
__attribute__((cleanup(cleanup_int))) int* x;
x = malloc(sizeof(int));
if (x != NULL) {
*x = 10;
}
/* s goes out of scope. Cleanup function called - no leak */
}
// related to https://github.com/facebook/infer/issues/8
void FP_cleanup_string_good() {
__attribute__((cleanup(cleanup_char))) char* s;
s = strdup("demo string");
/* s goes out of scope. Cleanup function called - no leak */
}
Loading…
Cancel
Save