[UFO-devel] ufo::UObject::trackPointer()
Status: Beta
Brought to you by:
schmidtjf
From: Andreas B. <b_...@gm...> - 2005-08-22 03:41:52
|
Hi there is a problem with ufo::UObject::trackPointer() versus ufo::UObject::releasePointer(): trackPointer() adds and references the given pointer unconditionally. However releasePointer() _releases_ the pointer once, but _removes_ it as often as it appears in the list. So something like trackPointer(foo); trackPointer(foo); releasePointer(foo); causes a memory leak: even if you have a second releasePointer(foo) in the code, it won't be able to actually release the pointer. ufo::UObject::releasePointer() also doesn't give any warning about this, so that such a bug would be very hard to find. The attached patch is an example of such a warning. I propose to additionally call unreference() as often as actually required (i.e. oldsize - m_pointers.size() times). With such a patch the above error message may not be required, depending on whether this kind of use is supposed to be allowed. Last but not least: ufo::UComboBox c'tors trigger this bug: trackPointer(m_textEdit); add(getTextEdit()); where getTextEdit() returns m_textEdit. ufo::UWidget::addImpl() calls trackPointer() nearly unconditionally and always does in this case. CU Andi |