How did I live without valgrind? It so useful!
To be honest I am very careful with coding and rarely hit memory leaks. My background has been in embedded software which means being very careful.
However, we had a memory leak in the call handling code. Not serious, and picked up by our monitoring anyway. Just using up a few bytes every now and then so that after some days you could see it was using noticeably more memory.
Buggered if I can find it, so (at Cliff's suggestion) I tried valgrind. It is already installed on the machine as standard it seems. All I had to do was run the app with valgrind on the start of the command line; leave it a few seconds to "leak" a bit; stop it; and valgrind says where the leak is. It could not be simpler to use...
Knowing where to look - it was, of course, blindingly obvious. An exception case did not free something, but that was happening every time an authenticated SIP request came in.
So +1 for valgrind. Well worth using if you have any suspicion that you have a memory leak in your code. Very cool.
P.S. Apologies to my sister-in-law and other non-techies as this will have made no sense whatsoever and I really could not find a way to explain it in simpler terms, so didn't even try... :-)
2010-08-04
Subscribe to:
Post Comments (Atom)
Fun with... LED Strips
I am not late to the party here, honest. I have been playing with these for some time, and even design and make LED controllers. The ubiquit...
-
Broadband services are a wonderful innovation of our time, using multiple frequency bands (hence the name) to carry signals over wires (us...
-
For many years I used a small stand-alone air-conditioning unit in my study (the box room in the house) and I even had a hole in the wall fo...
-
It seems there is something of a standard test string for anti virus ( wikipedia has more on this). The idea is that systems that look fo...
Then again you could use a language with garbage collection. :-) That would avoid problems with memory leaks and also the more serious problem where you carry on using memory that has been freed.
ReplyDeleteFor application level code on general purpose hardware, is there any reason to use C these days?
Come on - C is excellent :-)
ReplyDeletethanks for the kind thoughts lol your followers must think what a thicko you have for a sister-in-law but i don't mind Im still your fav one ha ha x
ReplyDeletePeteX, valgrind detects use-after-free as well. It also detects use-uninitialized on the *single bit* level. (And that's just the memcheck tool.)
ReplyDeleteRevK, GCC's -fmudflap option might also be worth investigating. (See the GCC docs). It's a compile-time instrumentation option which (unlike valgrind) can detect overruns of stack-allocated objects. (It's not a security option, though, unlike -fstack-protector, not least because it's much too expensive.)
(And, yes, valgrind is utterly sodding awesome. It's spotted many hundreds of bugs in the code I write at work and probably millions across the free software world. I recommend the valgrind paper, too, because the way it works -- dynamic decompilation to an instrumentable intermediate language, instrumentation, then recompilation again, all completely transparently to the user -- is incredibly nifty.)