Copilot commented on code in PR #53164:
URL: https://github.com/apache/doris/pull/53164#discussion_r2203947705
##########
be/src/olap/rowset/segment_v2/inverted_index_fs_directory.cpp:
##########
@@ -673,15 +674,22 @@ lucene::store::IndexOutput*
DorisFSDirectory::createOutput(const char* name) {
assert(!exists);
}
auto* ret = _CLNEW FSIndexOutput();
+ ErrorContext error_context;
ret->set_file_writer_opts(_opts);
try {
ret->init(_fs, fl);
} catch (CLuceneError& err) {
- ret->close();
- _CLDELETE(ret)
- LOG(WARNING) << "FSIndexOutput init error: " << err.what();
- _CLTHROWA(CL_ERR_IO, "FSIndexOutput init error");
- }
+ error_context.eptr = std::current_exception();
+ error_context.err_msg.append("FSIndexOutput init error: ");
+ error_context.err_msg.append(err.what());
+ LOG(ERROR) << error_context.err_msg;
+ }
+ FINALLY_EXCEPTION({
+ if (error_context.eptr) {
+ FINALLY_CLOSE(ret);
+ _CLDELETE(ret);
+ }
+ })
return ret;
Review Comment:
After the FINALLY_EXCEPTION block, \`ret\` may have been deleted when
\`error_context.eptr\` is set, leading to a use-after-free. Consider reworking
the error handling to avoid returning a deleted pointer, for example by
returning nullptr on failure or delaying deletion until after the return.
```suggestion
ret = nullptr; // Set ret to nullptr instead of deleting it
}
})
return ret; // Return nullptr if an exception occurred
```
##########
be/src/olap/rowset/segment_v2/inverted_index_compound_reader.cpp:
##########
@@ -296,7 +292,7 @@ bool DorisCompoundReader::fileExists(const char* name)
const {
if (_closed || _entries == nullptr) {
_CLTHROWA(CL_ERR_IO, "DorisCompoundReader is already closed");
}
- return _entries->exists((char*)name);
+ return _entries->find(std::string(name)) != _entries->end();
Review Comment:
[nitpick] Constructing a temporary \`std::string\` on each call can be
inefficient. Consider caching the lookup key or using a \`string_view\`-based
lookup if the map is updated to support it to reduce allocations.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]