purple: switch to deferred destruction approach
Over the years we have tried to fix various crashes by adding
PURPLE_CONNECTION_IS_VALID() calls here and there. But still SIPE keeps
crashing in corner cases.
Take a page from the telepathy backend development and switch DNS Query
& transport descruction to a deferred descruction approach:
- in constructor:
* set is_valid = TRUE
* add data structure to list of queries/transports
- all callbacks from libpurple now check is_valid before continuing
- in destructor:
* remove data structure from list of queries/transports
* closes all associated resources (as before)
* set is_valid = FALSE
* schedule deferred descructor with g_idle_add()
- in deferred detructor:
* all (possible) pending events have been processed already
* it is now safe to call g_free() on the data structure
I have tried to crash Pidgin by randomly disabling the account during
various phases of the connection setup, but I can't get it to crash
anymore.