Review feedback: Refactor device path derivation.

And fix reference leaks.
Review feedback: Minimise event check thread race during shutdown.

Theoretically, the event check could fire during unmount, resulting
in access to invalid backend state. We can try and minimise the
chance of this happening but can't elimiate it completely as the
LIBMTP_Read_Event call cannot occur with a lock or ref held as it
blocks and cannot be interrupted as part of the shutdown process.
If a lock was held, it would lead to a deadlock, and if a ref was
held, the backend would never finalize.

As it is, the race is now narrowed so that it's only applicable if
the unmount occurs at the point between where the MTP device is
looked up and when Read_Event is called.

And even before this change the race was incredibly rare as you'd
have to induce an MTP event in the middle of unmounting.

Finally, crashing while trying to terminate isn't the end of the
world.