Page MenuHomePhabricator

Ensure correct pattern of mitk::WeakPointer::Lock()
Open, HighPublic


There are several places in the code that have the following pattern:

  smartPointer = weakPointer.Lock();
 //do something with the smartPointer

This is not safe. As you have no guarantee that the weakPointer is valid in the next line. If you plan to use the weakPointer and want to be sure that you can use it, you have to do the following:

smartPointer = weakPointer.Lock();
  //do your stuff

In addition we should extend the documentation of mitk::WeakPointer::IsExpired() to stress the correct behavior. You should IsExpired() if you realy just want to know if the pointer is gone or not.

Event Timeline

floca triaged this task as High priority.Feb 15 2020, 9:51 AM
floca created this task.