Closed Bug 38776 Opened 25 years ago Closed 25 years ago

Potential Leak: OleUninitialize() isn't called for each OleInitialize()

Categories

(SeaMonkey :: UI Design, defect, P3)

x86
Windows NT
defect

Tracking

(Not tracked)

VERIFIED FIXED

People

(Reporter: deanis74, Assigned: rods)

Details

(Keywords: memory-leak)

nsWindow::StandardWindowCreate() calls OleInitialize() and sets gOLEInited = TRUE. For each of these calls to OleInitialize, there should be a matching call to OleUnitialize. To quote from MSDN (http://msdn.microsoft.com/library/psdk/com/ofn_ol2z_13vp.htm): "The OleInitialize and OleUninitialize calls must be balanced — if there are multiple calls to the OleInitialize function, there must be the same number of calls to OleUninitialize: Only the OleUninitialize call corresponding to the OleInitialize call that actually initialized the library can close it."
jrgm, would you know how to narrow this one down? thx!
Status: UNCONFIRMED → NEW
Ever confirmed: true
Keywords: mlk
QA Contact: sairuh → jrgm
Whoops. I'm dropping the status down to normal because I somehow missed that this is called only if gOLEInited is not TRUE. But it still needs to be cleaned up somewhere, probably on app exit.
Severity: major → normal
My best guess from lxr is that this is code that rods has worked with at least. However, I'm not going to guess whether this is a problem, or what the solution would be. Wanna propose a patch, Dean?
Assignee: don → rods
There's a couple of things that can be done. One is to call OleUnitialize() in nsWindow::Destroy() and reset the gOleInited flag, but that would then cause OleInitialize to be called with the next StandardWindowCreate(). This would make sure that each OleInit was paired with an OleUninit, but it would overdo it on the calls to OleInit. The better way to do it would be when the app shuts down completely. If gOleInited == TRUE, call OleUnitialize() and set gOleInited = FALSE. But I'm not sure where in the code this would be done.
gOLEInited is a global variable and OleInitialize is only called once. marking invalid
Status: NEW → RESOLVED
Closed: 25 years ago
Resolution: --- → INVALID
OleUninitialize should still be called on app exit.
OleUninitialize is not being called
Status: RESOLVED → REOPENED
Resolution: INVALID → ---
I realize that. My question is why isn't it being called?
Sorry Rod. I missed that you re-opened the bug with your last comment.
it now get properly inited and uninitied - fixed
Status: REOPENED → RESOLVED
Closed: 25 years ago25 years ago
Resolution: --- → FIXED
Target Milestone: --- → M16
Does OleRegisterMgr::~OleRegisterMgr() get called on shutdown? Is there a way that it can reset the gOleInited variable?
Because it is a global object it gets created very early on and then gets destroyed at the very end. I could have put a counter in nsWindow to count the number of constructs and destructs but decided that this approach was safer.
Well then there's still a little problem. OleInitialize will get called twice and OleUninitialize only once. The first time OleInit gets called is in OleRegisterMgr::OleRegisterMgr() and the second time is in the first nsWindow::StandardWindowCreate(). A suggestion is to get rid of the call in StandardWindowCreate() if OleRegisterMgr is always created very early on.
> second time is in the first nsWindow::StandardWindowCreate() That was removed in the same checkin that added the new class, no? There is only one call to OleInitialize possible.
Yes, it was removed and now there is only one call to each
Stupid me. Asked before I look. Apologies.
Yeah, but it made me look :-]
Status: RESOLVED → VERIFIED
No, problem. I didn't realize we were never doing the uninit, thanks for the help.
Product: Core → Mozilla Application Suite
You need to log in before you can comment on or make changes to this bug.