forked from abacusmodeling/abacus-develop
-
Notifications
You must be signed in to change notification settings - Fork 219
memory leak of libxc module #7204
Copy link
Copy link
Open
Labels
BugsBugs that only solvable with sufficient knowledge of DFTBugs that only solvable with sufficient knowledge of DFT
Description
Describe the bug
Agent 在代码库中找到了内存泄漏的根本原因:
🔴 核心问题:finish_func 函数按值遍历导致泄漏
文件: /personal/code/abacus-develop/source/source_hamilt/module_xc/xc_functional_libxc.cpp
问题代码 (第 290 行):
1 void XC_Functional_Libxc::finish_func(std::vector<xc_func_type> &funcs)
2 {
3 for(xc_func_type func : funcs) // ❌ 按值遍历,创建的是副本
4 {
5 xc_func_end(&func); // 清理的是副本,原对象未释放!
6 }
7 }
修复方法:
1 for(xc_func_type& func : funcs) // ✅ 按引用遍历
影响范围
这个 Bug 导致所有调用 init_func() 分配的 Libxc 内存都无法正确释放。受影响的调用点包括:
┌───────────────────────────────────┬───────────────────────────────┐
│ 文件 │ 函数 │
├───────────────────────────────────┼───────────────────────────────┤
│ xc_functional.cpp │ output_info() │
│ xc_functional_libxc_vxc.cpp │ v_xc_libxc(), v_xc_meta() │
│ xc_functional_libxc_wrapper_gcxc.cpp │ gcxc_libxc(), gcxc_spin_libxc() │
│ xc_functional_libxc_wrapper_tauxc.cpp │ tau_xc(), tau_xc_spin() │
│ xc_functional_libxc_wrapper_xc.cpp │ xc_spin_libxc() │
│ write_libxc_r.cpp │ XC 输出函数 │
│ xc_kernel.cpp │ f_xc_libxc() │
└───────────────────────────────────┴───────────────────────────────┘
关于 xc_functional_get_name
排查确认这个函数不是泄漏源——它返回的是 Libxc 的静态字符串,不是动态分配的内存。
关于 ompi_op_base_op_select
这是 OpenMPI 内部的内存分配,通常用于 MPI 归约操作。这类泄漏往往是 MPI
库自身在程序退出时未完全清理,属于常见的"假阳性"泄漏。
Expected behavior
No response
To Reproduce
No response
Environment
No response
Additional Context
No response
Task list for Issue attackers (only for developers)
- Verify the issue is not a duplicate.
- Describe the bug.
- Steps to reproduce.
- Expected behavior.
- Error message.
- Environment details.
- Additional context.
- Assign a priority level (low, medium, high, urgent).
- Assign the issue to a team member.
- Label the issue with relevant tags.
- Identify possible related issues.
- Create a unit test or automated test to reproduce the bug (if applicable).
- Fix the bug.
- Test the fix.
- Update documentation (if necessary).
- Close the issue and inform the reporter (if applicable).
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
BugsBugs that only solvable with sufficient knowledge of DFTBugs that only solvable with sufficient knowledge of DFT