From a0168a6709b87ee01e233aff6428a3602bb772e7 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Sun, 22 May 2016 13:38:22 +1000 Subject: [PATCH] Ensure nothing is preserved if previously allocated Former-commit-id: d83f70acf8d55f37023f84aa46b5918db3b44477 Former-commit-id: aa82f2434e299dfdc5da233d2134e40f5cba563e Former-commit-id: 501d485d858549d12cd406fe855e18a9a00c3282 --- src/ImageProcessorCore/ImageBase.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/ImageProcessorCore/ImageBase.cs b/src/ImageProcessorCore/ImageBase.cs index 4d4541645..dd6d59c59 100644 --- a/src/ImageProcessorCore/ImageBase.cs +++ b/src/ImageProcessorCore/ImageBase.cs @@ -191,6 +191,14 @@ namespace ImageProcessorCore this.Width = width; this.Height = height; + // Ensure nothing is preserved if previously allocated. + if (this.pixelsHandle.IsAllocated) + { + this.pixelsArray = null; + this.pixelsHandle.Free(); + this.pixelsBase = null; + } + this.pixelsArray = pixels; this.pixelsHandle = GCHandle.Alloc(this.pixelsArray, GCHandleType.Pinned); this.pixelsBase = (float*)this.pixelsHandle.AddrOfPinnedObject().ToPointer();