Backport of:

From 4751b606fa38edc456d627140898a7ec679fcc24 Mon Sep 17 00:00:00 2001
From: Vladimir Mitrovic <vladimir.x.mitrovic@gmail.com>
Date: Wed, 5 Aug 2015 03:01:06 +0200
Subject: [PATCH] gdImageScaleTwoPass memory leak fix

Fixing memory leak in gdImageScaleTwoPass, as reported by @cmb69 and
confirmed by @vapier.  This bug actually bit me in production and I'm
very thankful that it was reported with an easy fix.

Fixes #173.
---
 src/gd_interpolation.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Index: libgd2-2.1.0/src/gd_interpolation.c
===================================================================
--- libgd2-2.1.0.orig/src/gd_interpolation.c	2016-05-26 09:27:43.217119308 -0400
+++ libgd2-2.1.0/src/gd_interpolation.c	2016-05-26 09:28:30.473748958 -0400
@@ -1087,11 +1087,11 @@
 
 	dst = gdImageCreateTrueColor(new_width, new_height);
 	if (dst == NULL) {
-		gdFree(tmp_im);
+		gdImageDestroy(tmp_im);
 		return NULL;
 	}
 	_gdScaleVert(tmp_im, new_width, src_height, dst, new_width, new_height);
-	gdFree(tmp_im);
+	gdImageDestroy(tmp_im);
 
 	return dst;
 }
