From e5d6acd712aaedf595341e59d2aaa7cfb99f56eb Mon Sep 17 00:00:00 2001 From: gorhill Date: Sun, 28 Jun 2015 09:25:19 -0400 Subject: [PATCH] this fixes #391 --- src/js/logger.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/js/logger.js b/src/js/logger.js index 1a4692322..2ef03ede0 100644 --- a/src/js/logger.js +++ b/src/js/logger.js @@ -101,6 +101,14 @@ LogBuffer.prototype.dispose = function() { /******************************************************************************/ +LogBuffer.prototype.clearBuffer = function(beg, end) { + for ( var i = beg; i < end; i++ ) { + this.buffer[i] = null; + } +}; + +/******************************************************************************/ + LogBuffer.prototype.writeOne = function(args) { // Reusing log entry = less memory churning var entry = this.buffer[this.writePtr]; @@ -116,6 +124,13 @@ LogBuffer.prototype.writeOne = function(args) { // Grow the buffer between 1.5x-2x the current size if ( this.writePtr === this.readPtr ) { var toMove = this.buffer.slice(0, this.writePtr); + // https://github.com/gorhill/uBlock/issues/391 + // "The slice() method returns a shallow copy of a portion of an + // "array into a new array object." + // "shallow" => since we reuse entries, we need to remove the copied + // entries to prevent single instance of LogEntry being used in + // more than one slot. + this.clearBuffer(0, this.writePtr); var minSize = Math.ceil(this.size * 1.5); this.size += toMove.length; if ( this.size < minSize ) {