Skip to content

Commit

Permalink
[fix](inverted index) Fix incorrect exception handling (#243)
Browse files Browse the repository at this point in the history
Memory leaks may occur in exceptional situations
  • Loading branch information
zzzxl1993 authored Oct 14, 2024
1 parent 5e9566a commit 5a458e6
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions src/core/CLucene/index/IndexWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1308,21 +1308,6 @@ void IndexWriter::indexCompaction(std::vector<lucene::store::Directory *> &src_d
}
assert(readers.size() == numIndices);

// check hasProx
bool hasProx = false;
{
if (!readers.empty()) {
IndexReader* reader = readers[0];
hasProx = reader->getFieldInfos()->hasProx();
for (int32_t i = 1; i < readers.size(); i++) {
if (hasProx != readers[i]->getFieldInfos()->hasProx()) {
_CLTHROWA(CL_ERR_IllegalArgument, "src_dirs hasProx inconformity");
}
}
}
}
// std::cout << "hasProx: " << hasProx << std::endl;

numDestIndexes = dest_dirs.size();

// print dest index files
Expand All @@ -1342,6 +1327,20 @@ void IndexWriter::indexCompaction(std::vector<lucene::store::Directory *> &src_d
std::vector<lucene::index::IndexWriter *> destIndexWriterList;
std::vector<lucene::store::IndexOutput *> nullBitmapIndexOutputList;
try {
// check hasProx
bool hasProx = false;
{
if (!readers.empty()) {
IndexReader* reader = readers[0];
hasProx = reader->getFieldInfos()->hasProx();
for (int32_t i = 1; i < readers.size(); i++) {
if (hasProx != readers[i]->getFieldInfos()->hasProx()) {
_CLTHROWA(CL_ERR_IllegalArgument, "src_dirs hasProx inconformity");
}
}
}
}

/// merge fields
mergeFields(hasProx);

Expand Down Expand Up @@ -1395,8 +1394,6 @@ void IndexWriter::indexCompaction(std::vector<lucene::store::Directory *> &src_d

/// merge null_bitmap
mergeNullBitmap(srcNullBitmapValues, nullBitmapIndexOutputList);
} catch (CLuceneError &e) {
throw e;
}
_CLFINALLY(
for (auto freqOutput
Expand Down

0 comments on commit 5a458e6

Please sign in to comment.