Merge ptrofimov branch to fix gmagick memory leak and segmentation errors