Skip to content

Commit

Permalink
Fix memleak in fsspool (#1115)
Browse files Browse the repository at this point in the history
  • Loading branch information
kallsyms authored Jun 29, 2023
1 parent baa31a5 commit 020827b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ absl::Status FsSpoolLogBatchWriter::FlushNoLock() {
return status;
}
}
cache_.mutable_records()->Clear();
// We assign a new LogBatch() object here instead of calling Clear() method to
// make sure the memory used by the cache_ is actually freed. It seems that
// internal implementation of protobuf has some very generous way of managing
// memory allocations and in certain scenarios it keeps objects for a very
// long time (forever?).
cache_ = santa::fsspool::binaryproto::LogBatch();
cache_.mutable_records()->Reserve(max_batch_size_);
return absl::OkStatus();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class FsSpoolLogBatchWriter {
absl::Mutex cache_mutex_;
santa::fsspool::binaryproto::LogBatch cache_ ABSL_GUARDED_BY(cache_mutex_);

absl::Status FlushNoLock() ABSL_SHARED_LOCKS_REQUIRED(cache_mutex_);
absl::Status FlushNoLock() ABSL_EXCLUSIVE_LOCKS_REQUIRED(cache_mutex_);
};

} // namespace fsspool
Expand Down

0 comments on commit 020827b

Please sign in to comment.