Skip to content

Commit

Permalink
Set current_ to keep invariant in error case
Browse files Browse the repository at this point in the history
The very first time output.Rotate() is called, current_ might be uninitialized.  If the open() call fails then, RETURN_IF_ERROR does not set it to a different value.  Later calls in Output::Write() will dereference current_ and crash.
  • Loading branch information
jpvlsmv authored Mar 12, 2021
1 parent 355604b commit 79e5c90
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion stenotype/aio.cc
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ Error Output::Rotate(const std::string& dirname, int64_t micros,
std::string name = HiddenFile(dirname, micros);
int fd = open(name.c_str(), O_CREAT | O_WRONLY | O_DSYNC | O_DIRECT, 0600);
LOG(INFO) << "Opening packet file " << name << ": " << fd;
RETURN_IF_ERROR(Errno(fd), "open");
RETURN_IF_ERROR(Errno(fd), (current_=NULL,"open") );
if (initial_size > 0) {
LOG_IF_ERROR(Errno(fallocate(fd, 0, 0, initial_size)), "fallocate");
}
Expand Down

0 comments on commit 79e5c90

Please sign in to comment.