Consume the entire enumerator before letting it go out of scope #939
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This diff seems to fix issue #614. I have replaced blnsvr.exe with a version that contains this patch, and the events are gone. I tested that blnsvr.exe built without this patch does exhibit the behavior. The service is running without any visible issues, but I have not been able to do a meaningful test of its functionality.
I compared the usage of IWbemServices:ExecQuery in memstat.cpp with other C++ code that uses the same API. The only material difference I noticed was that the other code used the form
which guarantees that the enumerator is consumed in its entirety. Apparently, the API doesn't clean up its own context unless all items are consumed and throws a hissy fit later on, and quite likely only on a few of the calls.
Please review the patch carefully. I think I got the indentation right according to the "When in Rome" rule, but I'm not positive. The patch is paranoid; the check for enumerator==NULL can probably be eliminated, and it could be made shorter.
I did not run the test suite.