From 5a59778bbcd6bde43ff745097bdd45a43d3108b1 Mon Sep 17 00:00:00 2001
From: Janne Koschinski <janne@kuschku.de>
Date: Sun, 18 Mar 2018 17:44:16 +0100
Subject: [PATCH] Improved imagick error

---
 main.go | 6 +++---
 util.go | 4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/main.go b/main.go
index ea1f573..dd51d1e 100644
--- a/main.go
+++ b/main.go
@@ -39,6 +39,7 @@ func processImage(config *Config, client *redis.Client, value string) {
 	errorChannel := make(chan error)
 
 	wand := imagick.NewMagickWand()
+	defer wand.Destroy()
 
 	err := wand.ReadImage(filepath.Join(config.SourceFolder, image.Id))
 	if err != nil {
@@ -46,6 +47,8 @@ func processImage(config *Config, client *redis.Client, value string) {
 	}
 
 	wandLinear := wand.Clone()
+	defer wandLinear.Destroy()
+
 	err = wandLinear.TransformImageColorspace(imagick.COLORSPACE_RGB)
 	if err != nil {
 		panic(err)
@@ -79,9 +82,6 @@ func processImage(config *Config, client *redis.Client, value string) {
 			Success: true,
 		})
 	}
-
-	wand.Destroy()
-	wandLinear.Destroy()
 }
 
 func main() {
diff --git a/util.go b/util.go
index 8a7422c..dbea138 100644
--- a/util.go
+++ b/util.go
@@ -13,8 +13,10 @@ func resize(wand *imagick.MagickWand, wandLinear *imagick.MagickWand, size Size,
 
 	if size.Width == 0 && size.Height == 0 {
 		mw = wand.Clone()
+		defer mw.Destroy()
 	} else {
 		mw = wandLinear.Clone()
+		defer mw.Destroy()
 
 		width := mw.GetImageWidth()
 		height := mw.GetImageHeight()
@@ -91,7 +93,5 @@ func resize(wand *imagick.MagickWand, wandLinear *imagick.MagickWand, size Size,
 
 	err = mw.WriteImage(target)
 
-	mw.Destroy()
-
 	return err
 }
-- 
GitLab