Apache Lucene open-source search software
LUCENE-3059: don't leak memory in TermState for pulsing/sep codecs
Michael McCandless60e5f02062e5
diff --git a/lucene/src/java/org/apache/lucene/index/codecs/pulsing/PulsingPostingsReaderImpl.java b/lucene/src/java/org/apache/lucene/index/codecs/pulsing/PulsingPostingsReaderImpl.javaindex 4b42caa244b..9acb75e1d85 100644--- a/lucene/src/java/org/apache/lucene/index/codecs/pulsing/PulsingPostingsReaderImpl.java+++ b/lucene/src/java/org/apache/lucene/index/codecs/pulsing/PulsingPostingsReaderImpl.java@@ -68,15 +68,8 @@ public class PulsingPostingsReaderImpl extends PostingsReaderBase {@Overridepublic Object clone() {- PulsingTermState clone;- clone = (PulsingTermState) super.clone();- if (postingsSize != -1) {- clone.postings = new byte[postingsSize];- System.arraycopy(postings, 0, clone.postings, 0, postingsSize);- } else {- assert wrappedTermState != null;- clone.wrappedTermState = (BlockTermState) wrappedTermState.clone();- }+ PulsingTermState clone = new PulsingTermState();+ clone.copyFrom(this);return clone;}@@ -90,8 +83,10 @@ public class PulsingPostingsReaderImpl extends PostingsReaderBase {postings = new byte[ArrayUtil.oversize(other.postingsSize, 1)];}System.arraycopy(other.postings, 0, postings, 0, other.postingsSize);- } else {+ } else if (wrappedTermState != null) {wrappedTermState.copyFrom(other.wrappedTermState);+ } else {+ wrappedTermState = (BlockTermState) other.wrappedTermState.clone();}// NOTE: we do not copy thediff --git a/lucene/src/java/org/apache/lucene/index/codecs/sep/SepPostingsReaderImpl.java b/lucene/src/java/org/apache/lucene/index/codecs/sep/SepPostingsReaderImpl.javaindex 4380003b754..d6fda7627da 100644--- a/lucene/src/java/org/apache/lucene/index/codecs/sep/SepPostingsReaderImpl.java+++ b/lucene/src/java/org/apache/lucene/index/codecs/sep/SepPostingsReaderImpl.java@@ -151,14 +151,8 @@ public class SepPostingsReaderImpl extends PostingsReaderBase {@Overridepublic Object clone() {- SepTermState other = (SepTermState) super.clone();- other.docIndex = (IntIndexInput.Index) docIndex.clone();- if (freqIndex != null) {- other.freqIndex = (IntIndexInput.Index) freqIndex.clone();- }- if (posIndex != null) {- other.posIndex = (IntIndexInput.Index) posIndex.clone();- }+ SepTermState other = new SepTermState();+ other.copyFrom(this);return other;}@@ -166,12 +160,28 @@ public class SepPostingsReaderImpl extends PostingsReaderBase {public void copyFrom(TermState _other) {super.copyFrom(_other);SepTermState other = (SepTermState) _other;- docIndex.set(other.docIndex);- if (freqIndex != null && other.freqIndex != null) {- freqIndex.set(other.freqIndex);+ if (docIndex == null) {+ docIndex = (IntIndexInput.Index) other.docIndex.clone();+ } else {+ docIndex.set(other.docIndex);+ }+ if (other.freqIndex != null) {+ if (freqIndex == null) {+ freqIndex = (IntIndexInput.Index) other.freqIndex.clone();+ } else {+ freqIndex.set(other.freqIndex);+ }+ } else {+ freqIndex = null;}- if (posIndex != null && other.posIndex != null) {- posIndex.set(other.posIndex);+ if (other.posIndex != null) {+ if (posIndex == null) {+ posIndex = (IntIndexInput.Index) other.posIndex.clone();+ } else {+ posIndex.set(other.posIndex);+ }+ } else {+ posIndex = null;}payloadFP = other.payloadFP;skipFP = other.skipFP;