Is there a way to connect a malloc / free function call from a C application, which he is?
As already mentioned, this is very platform specific. Most “portable” methods are described in the accepted answer to this question . A port on a platform other than posix needs to find a suitable replacement dlsym.
dlsym
Since you mention Linux / gcc, hooks for malloc will probably serve you better.
, . . gcc 4.8.2, , .
#include <stdlib.h> int main() { int* ip = malloc(sizeof(int)); double* dp = malloc(sizeof(double)); free(ip); free(dp); } void* malloc(size_t s) { return NULL; } void free(void* p) { }
malloc() free() ; , , , , .
malloc()
free()
, , , , ( , ).
, "", , malloc free :
malloc
free
#define malloc(x) my_malloc(x) #define free(x) my_free(x) void * my_malloc(size_t nbytes) { /* Do your magic here! */ } void my_free(void *p) { /* Do your magic here! */ } int main(void) { int *p = malloc(sizeof(int) * 4); /* calls my_malloc */ free(p); /* calls my_free */ }
C . .
malloc/ , . , .
Windows Detour. . C OS-, CreateThread, HeapAlloc .. .
CreateThread
HeapAlloc
This library is specific to Windows. On other platforms, most likely there are similar libraries.