Skip to content

Commit

Permalink
Merge pull request bellard#36 from justjake/jake--mem-leak-ios
Browse files Browse the repository at this point in the history
Fix issue where errors inside Scope.withScope were masked by scope.dispose error
  • Loading branch information
justjake authored May 2, 2021
2 parents ef8afda + 0acc262 commit e5cdf18
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 63 deletions.
55 changes: 55 additions & 0 deletions .yarn/releases/yarn-2.4.1.cjs

Large diffs are not rendered by default.

55 changes: 0 additions & 55 deletions .yarn/releases/yarn-sources.cjs

This file was deleted.

3 changes: 2 additions & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
nodeLinker: node-modules
yarnPath: .yarn/releases/yarn-sources.cjs

yarnPath: .yarn/releases/yarn-2.4.1.cjs
33 changes: 31 additions & 2 deletions ts/lifetime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,27 @@ export class WeakLifetime<T, TCopy = never, Owner = never> extends Lifetime<T, T
}
}

function scopeFinally(scope: Scope, blockError: Error | undefined) {
let disposeError: Error | undefined
try {
scope.dispose()
} catch (error) {
disposeError = error
}

if (blockError && disposeError) {
Object.assign(blockError, {
message: `${blockError.message}\n Then, failed to dispose scope: ${disposeError.message}`,
disposeError,
})
throw blockError
}

if (blockError || disposeError) {
throw blockError || disposeError
}
}

/**
* Scope helps reduce the burden of manually tracking and disposing of
* Lifetimes. See [[withScope]]. and [[withScopeAsync]].
Expand All @@ -173,10 +194,14 @@ export class Scope implements Disposable {
*/
static withScope<R>(block: (scope: Scope) => R): R {
const scope = new Scope()
let blockError: Error | undefined
try {
return block(scope)
} catch (error) {
blockError = error
throw error
} finally {
scope.dispose()
scopeFinally(scope, blockError)
}
}

Expand All @@ -188,10 +213,14 @@ export class Scope implements Disposable {
*/
static async withScopeAsync<R>(block: (scope: Scope) => Promise<R>): Promise<R> {
const scope = new Scope()
let blockError: Error | undefined
try {
return await block(scope)
} catch (error) {
blockError = error
throw error
} finally {
scope.dispose()
scopeFinally(scope, blockError)
}
}

Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

__metadata:
version: 4
cacheKey: 6
cacheKey: 7

"@types/emscripten@npm:^1.38.0":
version: 1.38.0
Expand Down Expand Up @@ -712,10 +712,10 @@ __metadata:

"fsevents@patch:fsevents@~2.1.1#builtin<compat/fsevents>":
version: 2.1.3
resolution: "fsevents@patch:fsevents@npm%3A2.1.3#builtin<compat/fsevents>::version=2.1.3&hash=495457"
resolution: "fsevents@patch:fsevents@npm%3A2.1.3#builtin<compat/fsevents>::version=2.1.3&hash=11e9ea"
dependencies:
node-gyp: latest
checksum: 0005677b72f38a129a3cbe8c3794bdc83081a2bec53dfc03b085c2e5e4ca7a33a861a779d623313652df89746d97f79d24e4fef3b101c11c39ce1ea8a9690e18
checksum: e2b8c379340e21a786d32c653854c8876f94eb1202dd5be378fd42c062bc123aab5051c32bf0011865257c85982c41ded203f9fe8c9f9c8f8c84dc4672abc0e0
languageName: node
linkType: hard

Expand Down Expand Up @@ -2184,11 +2184,11 @@ resolve@^1.1.6:

"typescript@patch:[email protected]#builtin<compat/typescript>, typescript@patch:typescript@^3.7.4#builtin<compat/typescript>":
version: 3.7.4
resolution: "typescript@patch:typescript@npm%3A3.7.4#builtin<compat/typescript>::version=3.7.4&hash=5b02a2"
resolution: "typescript@patch:typescript@npm%3A3.7.4#builtin<compat/typescript>::version=3.7.4&hash=a45b0e"
bin:
tsc: ./bin/tsc
tsserver: ./bin/tsserver
checksum: 7f0e45c981f3a1089cc602aa4c555a3a653cb61e08652270f6e824b0d369939b14170bd3886baae3b3633c0b587bb390304c2000c25e861ef887ac82d33dbd2d
checksum: a62f8cadd2a3c8481356a71a9bc22bbcbb0d8f673402442f887ac9d871f81b97f65bf80b44f8b3cb2fa3c3f18eb60481b2c94a1c144429db65503b39f70ceeb9
languageName: node
linkType: hard

Expand Down

0 comments on commit e5cdf18

Please sign in to comment.