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

Fix heap use after free ASAN/Valgrind #1535

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion include/rocksdb/utilities/lua/rocks_lua_compaction_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ class RocksLuaCompactionFilter : public rocksdb::CompactionFilter {
explicit RocksLuaCompactionFilter(const RocksLuaCompactionFilterOptions& opt)
: options_(opt),
lua_state_wrapper_(opt.lua_script, opt.libraries),
error_count_(0) {}
error_count_(0),
name_("") {}

virtual bool Filter(int level, const Slice& key, const Slice& existing_value,
std::string* new_value,
Expand All @@ -180,6 +181,7 @@ class RocksLuaCompactionFilter : public rocksdb::CompactionFilter {
RocksLuaCompactionFilterOptions options_;
LuaStateWrapper lua_state_wrapper_;
mutable int error_count_;
mutable std::string name_;
};

} // namespace lua
Expand Down
10 changes: 6 additions & 4 deletions utilities/lua/rocks_lua_compaction_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ bool RocksLuaCompactionFilter::Filter(int level, const Slice& key,
}

const char* RocksLuaCompactionFilter::Name() const {
std::string name = "";
if (name_ != "") {
return name_.c_str();
}
auto* lua_state = lua_state_wrapper_.GetLuaState();
// push the right function into the lua stack
lua_getglobal(lua_state, kNameFunctionName.c_str());
Expand All @@ -146,7 +148,7 @@ const char* RocksLuaCompactionFilter::Name() const {
lua_tostring(lua_state, -1));
// pops out the lua error from stack
lua_pop(lua_state, 1);
return name.c_str();
return name_.c_str();
}

// check the return value
Expand All @@ -159,10 +161,10 @@ const char* RocksLuaCompactionFilter::Name() const {
const size_t name_size = lua_strlen(lua_state, -1);
assert(name_buf[name_size] == '\0');
assert(strlen(name_buf) <= name_size);
name = name_buf;
name_ = name_buf;
}
lua_pop(lua_state, 1);
return name.c_str();
return name_.c_str();
}

/* Not yet supported
Expand Down