blob: 9bd7509c94392c633939c74b016123159596b09e [file] [log] [blame]
Anastasia Klimchuk2daeea22021-03-04 09:54:56 +11001/*
2 * This file is part of the flashrom project.
3 *
4 * Copyright 2021 Google LLC
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
16/*
17 * This header is included in all files when they are built for unit test
18 * environment, for all the files to be covered by dynamic memory allocation
19 * checks (checks for memory leaks, buffer overflows and underflows).
20 *
21 * See flashrom_test_dep in meson.build for more details.
22 *
23 * https://api.cmocka.org/group__cmocka__alloc.html
24 */
25
26extern void* _test_malloc(const size_t size, const char* file, const int line);
27extern void* _test_realloc(void *ptr, const size_t size, const char* file, const int line);
28extern void* _test_calloc(const size_t number_of_elements, const size_t size,
29 const char* file, const int line);
30extern void _test_free(void* const ptr, const char* file, const int line);
31
32#ifdef malloc
33#undef malloc
34#endif
35#ifdef calloc
36#undef calloc
37#endif
38#ifdef realloc
39#undef realloc
40#endif
41#ifdef free
42#undef free
43#endif
44
45#define malloc(size) _test_malloc(size, __FILE__, __LINE__)
46#define realloc(ptr, size) _test_realloc(ptr, size, __FILE__, __LINE__)
47#define calloc(num, size) _test_calloc(num, size, __FILE__, __LINE__)
48#define free(ptr) _test_free(ptr, __FILE__, __LINE__)