TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Using ltrace to debug a memory leak

97 pointsby Dawny33almost 9 years ago

7 comments

scottlambalmost 9 years ago
Is there a convenient way to get a heap profile in Rust? I&#x27;d expect it shouldn&#x27;t be too hard. I&#x27;m used to using pprof with tcmalloc, jemalloc is based on tcmalloc, and Rust uses jemalloc by default.<p>pprof heap profiles make this kind of thing easy to debug. It draws a call graph using graphviz. Boxes are scaled according the total byte size, so if there&#x27;s a large leak you can pull up the graph and the giant box all but says &quot;you idiot, the problem is right here&quot;.
hywelalmost 9 years ago
This is my favourite kind of post to read: a tool I don&#x27;t know well, and someone using it enthusiastically to solve a real-world problem.
masklinnalmost 9 years ago
&gt; At this point I was tired so I fell asleep. This isn&#x27;t done, of course -- we still need to chase the Rust program to figure out why that allocation never gets freed. But it&#x27;s a start!<p>The type of .boxed() would probably help. I would expect a .boxed to return a Box&lt;_&gt; (e.g. Vec::into_boxed_slice(v) returns a Box&lt;[_]&gt;) which would get RAII-deallocated. So either .boxed() returns a raw pointer for some reason, or it properly returns a Box but leaks internally.
评论 #11909559 未加载
yoodenvranxalmost 9 years ago
I wish there would be a blog &#x2F; website which collects those kind of debugging stories. It would be a very valuable ressource for programmers.
评论 #11908644 未加载
评论 #11908859 未加载
majewskyalmost 9 years ago
Does Valgrind work with Rust binaries? If yes, then this would make everything much easier. You just compile in debug mode and say `valgrind --leak-check=full`, and it will give you stacktraces to the allocations that were not freed.
评论 #11910384 未加载
makomkalmost 9 years ago
Neat! Hadn&#x27;t come across this tool before but it let me track down a PulseAudio crash that&#x27;s been bugging me for months. Turns out that it was unloading a shared library whilst executing code from that shared library, which meant that the inevitable crash happened in code that was no longer loaded, and that was why I couldn&#x27;t get a meaningful backtrace at the time of the crash. The call to dlclose() right before the crash was a huge hint; knowing that was the last library function called made it easy to set a breakpoint and catch it in the act.<p>Thanks for the tip!
doomroboalmost 9 years ago
I&#x27;d be curious to see the full source code. A memory leak from an owned pointer should be impossible unless you&#x27;re using `unsafe` somewhere in your code or in a library you&#x27;re pulling in.
评论 #11913589 未加载