Skip to content
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

memory leak #76

Open
Six0Ne opened this issue Jan 22, 2024 · 4 comments
Open

memory leak #76

Six0Ne opened this issue Jan 22, 2024 · 4 comments

Comments

@Six0Ne
Copy link

Six0Ne commented Jan 22, 2024

Hello, in your code, I found two places that easily lead to memory leaks; 1. I noticed that the memory space and resources of wmi.enumerator were not released before each query was run. This can result in a new WMI enumerator object being created each time the query is run, without the old object being freed, resulting in a memory leak. 2. When calling the hr = obj->Get(L" ", 0, &vt_prop, nullptr, nullptr) function multiple times, a new vt_prop object will be created each time it is run. You only use VariantClear(&vt_prop) the last time ;In fact, this will only release one of the vt_prop objects. The correct approach should be to call obj->Get() every time, followed by VariantClear().
截图2

截图

@lfreist
Copy link
Owner

lfreist commented Jan 22, 2024

Hi @Six0Ne, thank you for reporting your concerns. I will evaluate your points.

Concerning your second point:
I am not a windows expert at all, so I may be wrong but calling hr = obj->Get(L" ", 0, &vt_prop, nullptr, nullptr) does not look like it is creating a vt_prop. We pass a memory address as argument and the function will use this address and overwrite existing data. We only need to free the address once, don't we? Or is obj->Get(...) allocating additional memory that is not freed on destruction?

@Six0Ne
Copy link
Author

Six0Ne commented Jan 23, 2024

Hello, I mean no harm; Regarding the second point, the theory is the same as what you said, we pass a memory address as a parameter, and the function will use that address and overwrite the existing data. We only need to release the address once; but in fact, doing so will indeed cause the memory to increase abnormally. As a simple test, put auto cpus = hwinfo::getAllCPUs(); into while(1) and run, we will find The memory of the program will grow abnormally;

@lfreist
Copy link
Owner

lfreist commented Jan 24, 2024

Well, doesn't look that nice indeed 😅

Feel free to submit a pull request. Else, I will try to approach the issue in the next few days. Thanks for the report!

@Six0Ne
Copy link
Author

Six0Ne commented Jan 25, 2024

Okay, please update it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants