Seems the problem is this rather evil bit of code in sp_dtw_desktop_shutdown:
if (doc && (((GObject *) doc)->ref_count == 1)) {
Guess I was right about having exposed an existing bug.
This is wrong for two reasons:
1. objects other than SPDesktops can reference SPDocuments, and there are non-inter-object-reference uses for refcounts: the wrong value being used for the wrong concept
2. GObject::ref_count is sort of an internal field (in the words of the glib API documentation, "All the fields in the GObject structure are private to the GObject implementation and should never be accessed directly.")
The most obvious fix is to specifically keep a count of related active desktops in the SPDocument, and do a similar test with that.
However, should we count SPDesktops, or more generally all SPViews (for example the preview view)?
Is SPDocument necessarily the place to actually keep track of that, or should it be e.g. the Inkscape Application object?
-mental