From d5ad62c5c74a3a895326cb3f9c6dc15fbd94f964 Mon Sep 17 00:00:00 2001 From: Matthew Williamson Date: Tue, 28 Jul 2020 10:39:22 -0700 Subject: [PATCH] Remote needs to REALLY persist the callback/proxyOpts/headers --- lib/remote.js | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/lib/remote.js b/lib/remote.js index 6106779e3..576ead232 100644 --- a/lib/remote.js +++ b/lib/remote.js @@ -8,6 +8,7 @@ var shallowClone = NodeGit.Utils.shallowClone; var Remote = NodeGit.Remote; var _connect = Remote.prototype.connect; var _createWithOpts = Remote.createWithOpts; +var _disconnect = Remote.prototype.disconnect; var _download = Remote.prototype.download; var _fetch = Remote.prototype.fetch; var _push = Remote.prototype.push; @@ -45,7 +46,29 @@ Remote.prototype.connect = function( proxyOpts = normalizeOptions(proxyOpts || {}, NodeGit.ProxyOptions); customHeaders = customHeaders || []; - return _connect.call(this, direction, callbacks, proxyOpts, customHeaders); + return _connect.call(this, direction, callbacks, proxyOpts, customHeaders) + .then(() => { + // Save options on the remote object. If we don't do this, + // the options may be cleaned up and cause a segfault + // when Remote.prototype.connect is called. + Object.defineProperties(this, { + callbacks: { + configurable: true, + value: callbacks, + writable: false + }, + proxyOpts: { + configurable: true, + value: proxyOpts, + writable: false + }, + customHeaders: { + configurable: true, + value: customHeaders, + writable: false + } + }); + }); }; Remote.createWithOpts = function(url, options) { @@ -53,6 +76,30 @@ Remote.createWithOpts = function(url, options) { options, NodeGit.RemoteCreateOptions)); }; +Remote.prototype.disconnect = function() { + return _disconnect.call(this) + .then(() => { + // Release the options + Object.defineProperties(this, { + callbacks: { + configurable: true, + value: undefined, + writable: false + }, + proxyOpts: { + configurable: true, + value: undefined, + writable: false + }, + customHeaders: { + configurable: true, + value: undefined, + writable: false + } + }); + }); +}; + /** * Connects to a remote *