From ea50d4fe8c1c3ff00fd84a2e10cf4ed307112c6a Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Wed, 10 Aug 2016 13:57:04 -0700 Subject: [PATCH] :non-potable_water: Fix leak in Workspace::buildTextEditor --- src/workspace.coffee | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/workspace.coffee b/src/workspace.coffee index 7f51a37d0..61da0a97a 100644 --- a/src/workspace.coffee +++ b/src/workspace.coffee @@ -561,10 +561,10 @@ class Workspace extends Model throw error @project.bufferForPath(filePath, options).then (buffer) => - editor = @buildTextEditor(Object.assign({buffer, largeFileMode}, options)) - disposable = atom.textEditors.add(editor) - editor.onDidDestroy -> disposable.dispose() - editor + new TextEditor(Object.assign( + {@clipboard, @assert, buffer, largeFileMode}, + options + )) handleGrammarUsed: (grammar) -> return unless grammar? @@ -581,10 +581,12 @@ class Workspace extends Model # # Returns a {TextEditor}. buildTextEditor: (params) -> - params = Object.assign({@clipboard, @assert}, params) - editor = new TextEditor(params) - @textEditorRegistry.maintainConfig(editor) - @textEditorRegistry.maintainGrammar(editor) + editor = new TextEditor(Object.assign({@clipboard, @assert}, params)) + subscriptions = new CompositeDisposable( + @textEditorRegistry.maintainConfig(editor), + @textEditorRegistry.maintainGrammar(editor) + ) + editor.onDidDestroy -> subscriptions.dispose() editor # Public: Asynchronously reopens the last-closed item's URI if it hasn't already been