Commit 0a5625f
committed
fix(test): fix memory leaks in test code
Fixed memory leaks in test code by adding proper destructors and cleanup:
1. Added destructor to TestModelA to release DataA objects stored in m_list
2. Added destructor to TestModelB to release DataB objects stored in m_list
3. Fixed QAbstractItemModelTester memory leak in RoleGroupModel.ModelTest
by adding delete statement
Also added AddressSanitizer and UndefinedBehaviorSanitizer flags to CMake
configuration for memory leak detection:
- Added -fsanitize=undefined,address to CXX_FLAGS and C_FLAGS
- Added -O0 -Wall -g -ggdb3 for debug builds
- Applied flags to both main CMakeLists.txt and tests/CMakeLists.txt
Log: Fixed memory leaks in test code and added sanitizer flags
Influence:
1. Run RoleCombineModel tests to verify no memory leaks
2. Run RoleGroupModel tests to verify QAbstractItemModelTester cleanup
3. Verify AddressSanitizer detects no leaks in test execution
4. Test that debug build works with new compiler flags
5. Verify all existing tests still pass with sanitizer enabled
fix(test): 修复测试代码中的内存泄漏
通过添加适当的析构函数和清理代码修复测试代码中的内存泄漏:
1. 为 TestModelA 添加析构函数以释放 m_list 中存储的 DataA 对象
2. 为 TestModelB 添加析构函数以释放 m_list 中存储的 DataB 对象
3. 在 RoleGroupModel.ModelTest 中添加 delete 语句修复 QAbstractItemModelTester 内存泄漏
同时向 CMake 配置添加了 AddressSanitizer 和 UndefinedBehaviorSanitizer 标志
用于内存泄漏检测:
- 向 CXX_FLAGS 和 C_FLAGS 添加 -fsanitize=undefined,address
- 添加 -O0 -Wall -g -ggdb3 用于调试构建
- 将标志应用到主 CMakeLists.txt 和 tests/CMakeLists.txt
Log: 修复测试代码内存泄漏并添加 sanitizer 标志
Influence:
1. 运行 RoleCombineModel 测试验证无内存泄漏
2. 运行 RoleGroupModel 测试验证 QAbstractItemModelTester 清理
3. 验证 AddressSanitizer 在测试执行中未检测到泄漏
4. 测试调试构建在新编译器标志下正常工作
5. 验证所有现有测试在启用 sanitizer 后仍能通过1 parent cfd112d commit 0a5625f
8 files changed
Lines changed: 31 additions & 2 deletions
File tree
- tests
- panels
- dock/taskmanager
- notification/server
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
27 | 33 | | |
28 | 34 | | |
29 | 35 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
5 | 11 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
46 | 52 | | |
47 | 53 | | |
48 | 54 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| 37 | + | |
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
46 | 52 | | |
47 | 53 | | |
48 | 54 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
71 | | - | |
| 71 | + | |
| 72 | + | |
72 | 73 | | |
73 | 74 | | |
74 | 75 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
32 | 34 | | |
33 | 35 | | |
34 | 36 | | |
| |||
0 commit comments