Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of cpputest by
include/CppUTest/MemoryLeakDetectorMallocMacros.h@3:9e8c8907d9ee, 2015-05-13 (annotated)
- Committer:
- Kojto
- Date:
- Wed May 13 13:20:35 2015 +0000
- Revision:
- 3:9e8c8907d9ee
- Parent:
- 0:0b799af9d58e
Rename console to mbed_cpputest_console (as in mbed testrunner)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rgrover1 | 0:0b799af9d58e | 1 | |
rgrover1 | 0:0b799af9d58e | 2 | /* |
rgrover1 | 0:0b799af9d58e | 3 | * This file can be used to get extra debugging information about memory leaks in your production code. |
rgrover1 | 0:0b799af9d58e | 4 | * It defines a preprocessor macro for malloc. This will pass additional information to the |
rgrover1 | 0:0b799af9d58e | 5 | * malloc and this will give the line/file information of the memory leaks in your code. |
rgrover1 | 0:0b799af9d58e | 6 | * |
rgrover1 | 0:0b799af9d58e | 7 | * You can use this by including this file to all your production code. When using gcc, you can use |
rgrover1 | 0:0b799af9d58e | 8 | * the -include file to do this for you. |
rgrover1 | 0:0b799af9d58e | 9 | * |
rgrover1 | 0:0b799af9d58e | 10 | */ |
rgrover1 | 0:0b799af9d58e | 11 | |
rgrover1 | 0:0b799af9d58e | 12 | #include "CppUTestConfig.h" |
rgrover1 | 0:0b799af9d58e | 13 | |
rgrover1 | 0:0b799af9d58e | 14 | #if CPPUTEST_USE_MEM_LEAK_DETECTION |
rgrover1 | 0:0b799af9d58e | 15 | |
rgrover1 | 0:0b799af9d58e | 16 | /* This prevents the declaration from done twice and makes sure the file only #defines malloc, so it can be included anywhere */ |
rgrover1 | 0:0b799af9d58e | 17 | #ifndef CPPUTEST_USE_MALLOC_MACROS |
rgrover1 | 0:0b799af9d58e | 18 | |
rgrover1 | 0:0b799af9d58e | 19 | #ifdef __cplusplus |
rgrover1 | 0:0b799af9d58e | 20 | extern "C" |
rgrover1 | 0:0b799af9d58e | 21 | { |
rgrover1 | 0:0b799af9d58e | 22 | #endif |
rgrover1 | 0:0b799af9d58e | 23 | |
rgrover1 | 0:0b799af9d58e | 24 | extern void* cpputest_malloc_location(size_t size, const char* file, int line); |
rgrover1 | 0:0b799af9d58e | 25 | extern void* cpputest_calloc_location(size_t count, size_t size, const char* file, int line); |
rgrover1 | 0:0b799af9d58e | 26 | extern void* cpputest_realloc_location(void *, size_t, const char* file, int line); |
rgrover1 | 0:0b799af9d58e | 27 | extern void cpputest_free_location(void* buffer, const char* file, int line); |
rgrover1 | 0:0b799af9d58e | 28 | |
rgrover1 | 0:0b799af9d58e | 29 | #ifdef __cplusplus |
rgrover1 | 0:0b799af9d58e | 30 | } |
rgrover1 | 0:0b799af9d58e | 31 | #endif |
rgrover1 | 0:0b799af9d58e | 32 | |
rgrover1 | 0:0b799af9d58e | 33 | extern void crash_on_allocation_number(unsigned number); |
rgrover1 | 0:0b799af9d58e | 34 | |
rgrover1 | 0:0b799af9d58e | 35 | #endif |
rgrover1 | 0:0b799af9d58e | 36 | |
rgrover1 | 0:0b799af9d58e | 37 | /* NOTE on strdup! |
rgrover1 | 0:0b799af9d58e | 38 | * |
rgrover1 | 0:0b799af9d58e | 39 | * strdup was implemented earlier, however it is *not* an Standard C function but a POSIX function. |
rgrover1 | 0:0b799af9d58e | 40 | * Because of that, it can lead to portability issues by providing more than is available on the local platform. |
rgrover1 | 0:0b799af9d58e | 41 | * For that reason, strdup is *not* implemented as a macro. If you still want to use it, an easy implementation would be: |
rgrover1 | 0:0b799af9d58e | 42 | * |
rgrover1 | 0:0b799af9d58e | 43 | * size_t length = 1 + strlen(str); |
rgrover1 | 0:0b799af9d58e | 44 | * char* result = (char*) cpputest_malloc_location(length, file, line); |
rgrover1 | 0:0b799af9d58e | 45 | * memcpy(result, str, length); |
rgrover1 | 0:0b799af9d58e | 46 | * return result; |
rgrover1 | 0:0b799af9d58e | 47 | * |
rgrover1 | 0:0b799af9d58e | 48 | */ |
rgrover1 | 0:0b799af9d58e | 49 | |
rgrover1 | 0:0b799af9d58e | 50 | #define malloc(a) cpputest_malloc_location(a, __FILE__, __LINE__) |
rgrover1 | 0:0b799af9d58e | 51 | #define calloc(a, b) cpputest_calloc_location(a, b, __FILE__, __LINE__) |
rgrover1 | 0:0b799af9d58e | 52 | #define realloc(a, b) cpputest_realloc_location(a, b, __FILE__, __LINE__) |
rgrover1 | 0:0b799af9d58e | 53 | #define free(a) cpputest_free_location(a, __FILE__, __LINE__) |
rgrover1 | 0:0b799af9d58e | 54 | |
rgrover1 | 0:0b799af9d58e | 55 | #define CPPUTEST_USE_MALLOC_MACROS 1 |
rgrover1 | 0:0b799af9d58e | 56 | #endif |