Search code examples
cmemoryvalgrind

Can't detect huge memory usage in C program


I am experiencing a huge memory usage when running my C program. It uses way more memory than it is expected to use. Even the OS sometimes has to kill the process due to a lot of memory usage (And I have 20GB of RAM in my machine). I try to run valgrind to see if there are some clues about what is going on with memory usage. Among the valgrind output, I can see a warning that might be pointing to the issue:

==69541== Warning: set address range perms: large range [0x76eb040, 0x2cb27240) (undefined)

However, I do not know how to know where is this large range of memory being allocated.

Hope this is not a too generic question. I tried to provide the minimum details to solve the issue, but if needed, I can provide more information.


Solution

  • I was able to find the problem. I post here the approach I used and worked for me, just in case it might be useful for someone else (although probably is not the neatest one).

    Using the debugger I spotted the place were the huge allocation was taking place (it was taking a lot of time). Then I realized that I was creating a hash-table object, which its size is passed as parameter. I was not passing the parameter, so the program was taking a garbage (big) number as the size.

    Thanks to all of you that shared your thoughts about my question :)