TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Finding memory leaks in Postgres C code

106 点作者 lichtenberger大约 1 年前

8 条评论

pornel大约 1 年前
You don&#x27;t need to wait until program&#x27;s exit. Valgrind has a GDB server that can be used to check for leaks during program&#x27;s runtime:<p><a href="https:&#x2F;&#x2F;valgrind.org&#x2F;docs&#x2F;manual&#x2F;mc-manual.html#mc-manual.monitor-commands" rel="nofollow">https:&#x2F;&#x2F;valgrind.org&#x2F;docs&#x2F;manual&#x2F;mc-manual.html#mc-manual.mo...</a>
评论 #39866139 未加载
hyperman1大约 1 年前
Valgrind has client requests, which you can use to teach it about custom mempools. This should make it possible to avoid the problems this author was having.<p>See manual chapter 4.7 and 4.8:<p><a href="https:&#x2F;&#x2F;valgrind.org&#x2F;docs&#x2F;manual&#x2F;mc-manual.html#mc-manual.clientreqs" rel="nofollow">https:&#x2F;&#x2F;valgrind.org&#x2F;docs&#x2F;manual&#x2F;mc-manual.html#mc-manual.cl...</a>
kccqzy大约 1 年前
The author&#x27;s definition of a leak is somewhat unusual. If a memory is allocated and eventually freed it&#x27;s not really a leak in the strict sense. That&#x27;s why the author is having so much trouble with typical tools like Valgrind or leak sanitizer: the definition of the leak is different!<p>I would approach this problem by using regular profiling. Collect a few memory profiles and see whether there&#x27;s any suspiciously large chunk of memory not yet freed.
评论 #39868277 未加载
评论 #39868271 未加载
pflanze大约 1 年前
After a cursory inspection of the memleak program source and Brendan Gregg&#x27;s blog post it&#x27;s still not clear to me what it is tracking to be able to decide that there&#x27;s a leak here. It would seem to me that palloc causes a mmap call for the initial allocation (or to enlarge the region?); but why would an individual allocation within the region be treated as a leak? I can see how eBPF can allow to track mmap usage for custom allocators where valgrind or ASAN might not (I&#x27;m not sure about that), but it being reported as a leak would imply that the whole region is missing a deallocation call? How would it recognize via eBPF tracing that 4 KB within the region remain without a pointer?<p>PS. My assumption here is that palloc is allocating within a region. Which is how OP describes it (oddly it doesn&#x27;t take a MemoryContext as an argument so that must be in some global or thread-local var, or palloc is a macro and takes the context from a lexical variable (uh)?).
fdr大约 1 年前
This is pretty interesting. I&#x27;m not sure if many commenters have abstracted this approach the way I would have, but it is sure is a handy trick to couple virtual memory related system calls (brk, mmap) to stack dumps and aggregation thereof, and it would not have been so easy to do in, say, 2009.
评论 #39869160 未加载
gkfasdfasdf大约 1 年前
jemalloc as well has some handy leak &#x2F; memory profiling abilities: <a href="https:&#x2F;&#x2F;github.com&#x2F;jemalloc&#x2F;jemalloc&#x2F;wiki&#x2F;Use-Case%3A-Heap-Profiling">https:&#x2F;&#x2F;github.com&#x2F;jemalloc&#x2F;jemalloc&#x2F;wiki&#x2F;Use-Case%3A-Heap-P...</a>
nwellnhof大约 1 年前
With LSan, you can use __lsan_do_recoverable_leak_check to get leak reports during run time.
评论 #39866783 未加载
评论 #39866143 未加载
archy_大约 1 年前
Would using Rust have prevented this?
评论 #39869969 未加载