On 04/12/2015 08:50 AM, julien2412 wrote:
I read about tdf#90566, Theme::disposing(void) memory leak:
maChangeListeners is not properly disposed and wondered why we couldn't just
remove the 2 first lines of the disposing function (see
http://opengrok.libreoffice.org/xref/core/sfx2/source/sidebar/Theme.cxx#390)
+ replace "aListeners" by "maChangeListeners"?
I mean why adding an intermediate variable instead of just using the initial
variable?

The general reason for this construct is multi-threading: Access to the maChangeListeners member typically needs to be guarded by some mutex (typically a member of the same class instance as maChangeListeners), and the calls "out of that instance" to the

  (*iListener)->disposing(aEvent);

must be done with that mutex not locked (to avoid deadlock). That is why the generic skeleton is

  Listeners copy;
  {
    Guard g(mMutex);
    copy = mListeners;
  }
  for (i: copy) i->...

However, in this particular case, the access to maChangeListeners is not guarded, but likely out of ignorance of the original author.

_______________________________________________
LibreOffice mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/libreoffice

Reply via email to