Skip to content

修复xy.h中所有可能导致潜在内存泄漏的代码#344

Open
Mikachu2333 wants to merge 1 commit intoRubyMetric:devfrom
Mikachu2333:dev
Open

修复xy.h中所有可能导致潜在内存泄漏的代码#344
Mikachu2333 wants to merge 1 commit intoRubyMetric:devfrom
Mikachu2333:dev

Conversation

@Mikachu2333
Copy link
Collaborator

问题描述

  1. 完全没看懂 Feature mempool #343 到底怎么修的内存泄露,于是自己又找了一遍,说实话我认为这是无效代码

方案与实现

  1. 修复所有未经处理的内存泄漏以及潜在的内存泄漏点(都是kb级别的,连很难想象现在的代码哪里有机会能漏到mb级别的内存)

@github-actions
Copy link

Hi @Mikachu2333

❤️ 感谢你的贡献!我们将在最少半小时,最多5天内阅读此 PR 并回复你

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

本 PR 聚焦于 lib/xy.h 中的内存管理问题修复,针对字符串处理、日志拼接、命令执行与路径工具函数,补齐释放与失败分支处理,从而减少潜在/实际的内存泄漏风险。

Changes:

  • 修复/完善若干函数的内存释放路径(如日志着色字符串、popen 失败分支、循环内重复分配等)。
  • 增强部分分配失败时的处理(如 xy_str_gsub 增加 malloc 失败返回、xy_run_get_stdout 增加 realloc 失败处理等)。
  • 修正 xy_parent_dir 在无分隔符路径场景下的泄漏与返回值处理。

You can also share your feedback on Copilot code review. Take the survey.

Copy link
Contributor

@ccmywish ccmywish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我建议 _xy_log()_xy_log_brkt() 先不要改,因为这样 free() 的频率太高了。

这两个函数(像这种懒得解决的)正是可以用 mempool 去管控的地方。

@ccmywish
Copy link
Contributor

完全没看懂 #343 到底怎么修的内存泄露

用的时机不对,不应该在 main 前后管理内存,这是程序级的管控,应该在函数级进行管控。

@ccmywish ccmywish mentioned this pull request Mar 17, 2026
@Mikachu2333
Copy link
Collaborator Author

我建议 _xy_log()_xy_log_brkt() 先不要改,因为这样 free() 的频率太高了。

这两个函数(像这种懒得解决的)正是可以用 mempool 去管控的地方。

说句实话,我其实都完全不想动这地方的,以当前的内存空间大小,漏这一点完全可理解……
并且有修这种地方的功夫不如琢磨琢磨怎么改进如何便捷地解析json等常见格式配置文件了

@Mikachu2333
Copy link
Collaborator Author

晚上改

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

改善加强 改善加强

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants