Skip to content

Commit

Permalink
Fix memory leak in GTMSessionFetcherService
Browse files Browse the repository at this point in the history
  • Loading branch information
leits committed Jun 29, 2023
1 parent b944f7a commit 7cfb65b
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions MeetingBar/EventStores/GCEventStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class GCEventStore: NSObject, EventStore, OIDExternalUserAgent {
static let shared = GCEventStore()

var auth: GTMAppAuthFetcherAuthorization?
lazy var fetcherService = GTMSessionFetcherService()

override private init() {
super.init()
Expand All @@ -45,10 +46,8 @@ class GCEventStore: NSObject, EventStore, OIDExternalUserAgent {
}

if let url = URL(string: "https://www.googleapis.com/calendar/v3/users/me/calendarList") {
let service = GTMSessionFetcherService()

service.authorizer = auth
service.fetcher(with: url).beginFetch { data, error in
fetcherService.authorizer = auth
fetcherService.fetcher(with: url).beginFetch { data, error in
if error != nil {
if [OIDOAuthTokenErrorDomain, OIDHTTPErrorDomain].contains((error as NSError?)?.domain) {
self.setAuthorization(auth: nil)
Expand Down Expand Up @@ -102,9 +101,8 @@ class GCEventStore: NSObject, EventStore, OIDExternalUserAgent {
let timeMax = formatter.string(from: dateTo)

if let url = URL(string: "https://www.googleapis.com/calendar/v3/calendars/\(calendar.ID)/events?singleEvents=true&orderBy=startTime&timeMax=\(timeMax)&timeMin=\(timeMin)") {
let service = GTMSessionFetcherService()
service.authorizer = auth
service.fetcher(with: url).beginFetch { data, error in
fetcherService.authorizer = auth
fetcherService.fetcher(with: url).beginFetch { data, error in
if error != nil {
if [OIDOAuthTokenErrorDomain, OIDHTTPErrorDomain].contains((error as NSError?)?.domain) {
self.setAuthorization(auth: nil)
Expand Down Expand Up @@ -309,6 +307,7 @@ class GCEventStore: NSObject, EventStore, OIDExternalUserAgent {
func signOut() -> Promise<Void> {
Promise { seal in
self.setAuthorization(auth: nil)
self.fetcherService.stopAllFetchers()
seal.fulfill(())
}
}
Expand Down

0 comments on commit 7cfb65b

Please sign in to comment.