From 68a2da70731ff7c033a7d6f626febf225d5e57a6 Mon Sep 17 00:00:00 2001 From: Tanner Nelson Date: Fri, 3 Feb 2017 13:16:11 +0100 Subject: [PATCH 1/2] fix cycle leak --- Sources/FormData/Parser.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/FormData/Parser.swift b/Sources/FormData/Parser.swift index 3fa8944..c13c349 100644 --- a/Sources/FormData/Parser.swift +++ b/Sources/FormData/Parser.swift @@ -23,7 +23,7 @@ public final class Parser { public init(multipart: Multipart.Parser) { self.multipart = multipart - self.multipart.onPart = { part in + self.multipart.onPart = { [weak self] part in if let contentDisposition = part.headers[.contentDisposition] { let parser = ContentDispositionParser() @@ -50,7 +50,7 @@ public final class Parser { if let name = name { let field = Field(name: name, filename: filename, part: part) - self.onField?(field) + self?.onField?(field) } } From 3d0d7da9dfa7ab08185d5dc4b9dfee6c098149c3 Mon Sep 17 00:00:00 2001 From: Tanner Nelson Date: Fri, 3 Feb 2017 13:22:25 +0100 Subject: [PATCH 2/2] no processing if self doesn't exist --- Sources/FormData/Parser.swift | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Sources/FormData/Parser.swift b/Sources/FormData/Parser.swift index c13c349..50c247e 100644 --- a/Sources/FormData/Parser.swift +++ b/Sources/FormData/Parser.swift @@ -24,7 +24,10 @@ public final class Parser { self.multipart = multipart self.multipart.onPart = { [weak self] part in - if let contentDisposition = part.headers[.contentDisposition] { + if + let contentDisposition = part.headers[.contentDisposition], + let welf = self + { let parser = ContentDispositionParser() var name: String? @@ -50,7 +53,7 @@ public final class Parser { if let name = name { let field = Field(name: name, filename: filename, part: part) - self?.onField?(field) + welf.onField?(field) } }