-
-
Notifications
You must be signed in to change notification settings - Fork 257
修复各种内存泄露以及资源未释放的问题 #300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
修复各种内存泄露以及资源未释放的问题 #300
Conversation
1. 改进了获取新创建文件名的方式 2. 改进了内存泄漏问题
这个 PR 有一部分和 #298 重复了 (创建临时文件) |
本来设计的时候就没打算处理内存,如果现在要考虑内存处理,需要谨慎。 除了不确定能否完全达到修复所有内存泄漏的问题以外,就单从更改范围性来看,可能会引入问题,而这些问题现有的测试无法排除,很有可能 而我们 所以该 PR 考虑在 |
单从代码上来看,质量很高 👍
另外,我依然希望,内存的释放尽量只停留在 而 |
是的,不过没有冲突,本pr一开始就是在本地merge的基础上继续修改的。 原因也很简单,一开始我写的时候也没想过内存泄露的问题,结果改tmpfile的时候越改发现问题越多,于是就只把tmpfile的逻辑修了,内存泄露与句柄回收之类的问题全塞这里了。
可以理解,完全支持
目前我只改了 core.c 和 xy.c 并且不打算扩大修正范围。 记混了,core就漏了一点点,如果你认为需要回退core那也没啥大问题
是的,我完全没有动各换源子项目的代码(我自己rust的也漏了一点其实),各菜谱漏一点都是可接受的、可预期的。只是我想在源头上尽量堵一堵,不然哪怕菜谱的代码圆满无缺,根子上还是四处漏风(
果然还是得感谢ai,让我写我是真写不出来,但是让我看看逻辑,看看stack overflow的例子,对着cpp reference和winapi docs看看函数用的对不对还是能做到的(
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR focuses on fixing memory leaks and resource management issues throughout the codebase. The primary goal is to ensure proper cleanup of dynamically allocated memory and file handles to prevent resource leaks.
Key changes:
- Added
xy_str_swap
helper function for safe string pointer replacement with automatic memory cleanup - Fixed multiple memory leaks by adding proper
free()
calls for allocated strings and file handles - Improved variable naming in file existence checking functions for better clarity
- Refactored string manipulation functions to prevent memory leaks
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
src/framework/core.c | Added missing free() calls for temporary file paths and URL strings, fixed file handle leak in error path |
lib/xy.h | Added xy_str_swap() helper function, refactored string functions to use proper memory management, improved variable naming in file/directory existence functions |
} | ||
else | ||
{ | ||
int status = system (xy_2strcat ("test -d ", dir)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Memory leak: The string returned by xy_2strcat()
is not freed after the system()
call.
int status = system (xy_2strcat ("test -d ", dir)); | |
char *cmd = xy_2strcat ("test -d ", dir); | |
int status = system (cmd); | |
free(cmd); |
Copilot uses AI. Check for mistakes.
有空的话看一下。 |
问题描述
方案与实现
xy_str_swap
用于释放旧指针的内存