Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MB-30342 - ref_count leak from FieldDict #960

Merged
merged 1 commit into from Jul 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions search/searcher/search_term_prefix.go
Expand Up @@ -27,13 +27,21 @@ func NewTermPrefixSearcher(indexReader index.IndexReader, prefix string,
if err != nil {
return nil, err
}
defer func() {
if cerr := fieldDict.Close(); cerr != nil && err == nil {
err = cerr
}
}()

var terms []string
tfd, err := fieldDict.Next()
for err == nil && tfd != nil {
terms = append(terms, tfd.Term)
tfd, err = fieldDict.Next()
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is another error unchecked here, using this pattern, we must check for non nil err upon exiting the loop, as we may have broken out of the for loop due to an error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

if err != nil {
return nil, err
}

return NewMultiTermSearcher(indexReader, terms, field, boost, options, true)
}
6 changes: 6 additions & 0 deletions search/searcher/search_term_range.go
Expand Up @@ -48,6 +48,12 @@ func NewTermRangeSearcher(indexReader index.IndexReader,
return nil, err
}

defer func() {
if cerr := fieldDict.Close(); cerr != nil && err == nil {
err = cerr
}
}()

var terms []string
tfd, err := fieldDict.Next()
for err == nil && tfd != nil {
Expand Down