Reputation: 189
I have a very unique problem, i am running Linux on a special hardware which is an Octeon based hardware. I see that my process keeps allocating memory upon performing a specific operation. I would like to track which part of the code is making this call.
Here is the details about my environment
However here are the my options/limitations that i need to work around.
Please suggest if there is some way to go about this.
Thanks a lot.
Another thing i forgot to mention, the virtual memory of the process goes on increasing up-to 1.4GB at which, it stops and i see the allocs in the code fail with ENOMEM. Is this 1.4 GB limitation something to do with 32 bit machine? AFAIU 32 bit machine should allow 3 GB of virtual memory per process isnt it? Also, there is no per process limitation, i have confirmed this with setrlimit/getrlimit.
Cheers, Pavan
Upvotes: 4
Views: 2027
Reputation: 206526
If you want to write an wrapper function over malloc
, You can do so without modifying each and every instance in your code where the function is called, a simple macro trick shall suffice:
void* my_malloc(size_t size, const char *file, int line, const char *func);
#define malloc(X) my_malloc( X, __FILE__, __LINE__, __FUNCTION__)
void* my_malloc(size_t size, const char *file, int line, const char *func)
{
void *p = malloc(size);
printf ("Allocated = %s, %i, %s, %p[%li]\n", file, line, func, p, size);
/*Link List functionality goes in here*/
return p;
}
Similarly, You can also map free
to call your own function.
You can maintain a list of allocated addresses and keep on adding new entries in malloc
and removing relevant entries from the list in free
. What remains in the list at the end of the program is leaking memory with locations.
Upvotes: 5