Skip to content

Commit

Permalink
Stop leaking memory by avoiding retain cycle in callback (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
djones6 authored May 14, 2018
2 parents 9858956 + 99edf90 commit 5cf5810
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Sources/Credentials/Credentials.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,12 @@ public class Credentials : RouterMiddleware {
let plugin = self.nonRedirectingPlugins[pluginIndex]
plugin.authenticate(request: request, response: response, options: self.options,
onSuccess: { userProfile in
callback = nil
request.userProfile = userProfile
next()
},
onFailure: { status, headers in
callback = nil
self.fail(response: response, status: status, headers: headers)
},
onPass: { status, headers in
Expand All @@ -99,13 +101,15 @@ public class Credentials : RouterMiddleware {
callback!()
},
inProgress: {
callback = nil
self.redirectUnauthorized(response: response)
next()
}
)
}
else {
// All the plugins passed
callback = nil
if request.session != nil, !self.redirectingPlugins.isEmpty {
Credentials.setRedirectingReturnTo(request.originalURL, for: request)
self.redirectUnauthorized(response: response)
Expand Down

0 comments on commit 5cf5810

Please sign in to comment.