I am currently working on a C networking application for linux. It is based on DPDK. I've executed the app using valgrind which does not show any memory leaks. I've also tried Intel Inspector 2016, with the same results. But when I let my app run on a system (AWS EC2 instance) for a couple of days while monitoring the RAM usage(Cloudwatch), it shows the RAM increasing constantly, linearly and slowly(about 1 MB/day). How can I find this leak?
Asked
Active
Viewed 268 times
-1
-
8Exactly - how can we find out this leak? You haven't posted any code. – abhishek_naik May 21 '16 at 11:39
-
Post code which you suspect most. – Ahmed Akhtar May 21 '16 at 11:41
-
I cannot post the code. Its a very large codebase. And I've been looking for the leak for a couple of days now, nowhere near finding it? Just need some ideas about what could be done if valgrind and other such tools cannot do the job. – Vineet May 21 '16 at 12:02
-
1How do you know you have a memory leak? The fact that memory increases doesn't not mean you have a leak. You don't have a leak until you have lost all pointers to an allocated area. – Support Ukraine May 21 '16 at 12:04
-
@sjsam Just how is he/she supposed to give you a minimal working example? It's likely a huge program and the author has no idea where the leak is happening. What should one do, paste the github link? He is obviously asking for common causes for a general problem and the question is a valid one. – Einheri May 21 '16 at 12:05
-
1No, it's not a valid question. We cannot debug distributed systems by blog. The ONLY way is hands-on, in-situ, with engineers who are skilled in testing and debugging such systems and, even then, it's very difficult:( With all the code, debuggers, logs, test data, test harnesses, test apps and offline versions, its' still very, very difficult. – Martin James May 21 '16 at 12:22
-
@4386427 I ran my application in an isolated EC2 instance on AWS, and every 30 seconds I am logging available and used RAM. The graph of used RAM is slowly increasing. – Vineet May 21 '16 at 12:24
-
@Vineet - still, increasing RAM usage isn't the same as a memory leak – Support Ukraine May 21 '16 at 12:26
-
@MartinJames I am just looking for ideas, mate. What would could be done in such a case. Asking for a little help. Does that make it an invalid question? – Vineet May 21 '16 at 12:27
-
@4386427 If just my application and nothing else is running on an instance(server) and the RAM usage is increasing steadily, doesn't it imply that the application is the culprit? – Vineet May 21 '16 at 12:38
-
a memory leak can only happen if there are more calls to `malloc()` plus `calloc()` as compared to the number of calls to `free()`. Note: calls to `realloc()` "usually" result in more memory being allocated. All the memory leak problem is in these 4 system calls. Note: overrunning a allocated memory buffer or corrupting a pointer to that memory will create problems that can look like a memory leak. Note: the checking must include when any of these functions are called multiple times from the same location in the code, like in loops or a sub function that is repeatedly called – user3629249 May 23 '16 at 00:13
1 Answers
4
One way to debug this is to write some code that monitors all memory allocations and all de-allocation. With such monitor code, you'll be able to find "where" the allocated memory is.
Since you are using Linux, this may be a place to start:
http://www.gnu.org/savannah-checkouts/gnu/libc/manual/html_node/Hooks-for-Malloc.html
A first test could be to check whether all allocated memory is free'd when the program is closed. This will tell whether you have a leak or a build up of used memory.

Support Ukraine
- 42,271
- 4
- 38
- 63
-
Thanks a lot. I was looking for something like this. I'll try this out. – Vineet May 21 '16 at 12:29