Fix crashes and leaks in Azure and Skia

Fixes #979.