Ticket URL: <
http://trac.wxwidgets.org/ticket/14293#comment:6>
#14293: Resource leak in wxAutomationObject::Invoke() if argument conversion fails
-----------------------------------------------------+----------------------
Reporter: PB | Owner:
Type: defect | Status: confirmed
Priority: low | Milestone:
Component: wxMSW | Version: 2.9-svn
Keywords: Automation, OLE, VARIANT, resource leak | Blockedby:
Patch: 0 | Blocking:
-----------------------------------------------------+----------------------
Comment(by PB):
Vadim, it's probably because of my broken English but I think we are not
on the same page, so please let my try to reiterate the problem.
I reported the bug because of a possible memory leak: in case of an error
in converting the wxVariant argument to OLE VARIANT, the already
converted VARIANTs were not cleared (!VariantClear()), which would result
in leaks if any of the already converted VARIANTs contained a SAFEARRAY,
BSTR or IDispatch pointer.
The patch proposed in my first post deals with that for !SafeArrays and
BSTRs. But there is still an inconsistency when it comes to treating
wxVariants containing IDispatch pointers. The current implementation of
wxAutomationObject::Invoke() decreases the reference count of IDispatches
passed to it as arguments in wxVariants (if all the arguments were
successfully converted to OLE VARIANTs). The programmer learns very fast
about this (I certainly did when I my code started crashing because of
invalid pointers) and has to work around it, which often means adding an
extra IDispatch->!AddRef() call. If what you suggest is implemented, the
reference count of dispatches passed as arguments to
wxAutomationObject::Invoke() won't be changed which would mean the current
3rd party code could after recompiling with the updated wxWidgets start
leaking dispatches left and right.
With all that said, I believe the proper solution would be:
1. Do not alter behaviour of wxConvertVariantToOle(), it's too late to do
that now.
2. Make wxAutomation::Invoke() behaviour consistent: always decrease the
ref count of IDispatch pointers passed to it as arguments, regardless of
success of converting all its arguments to VARIANTs. I don't think anyone
would account for the current inconsistent behaviour (which of course
doesn't mean that the fix can't expose a bug in the user code which
happens to rely on the bug >.< ).
--
Ticket URL: <
http://trac.wxwidgets.org/ticket/14293#comment:6>