Browse Source

log_writer_file: make sure to close the file

and avoid doing a loop iteration when the thread is requested to exit
(as it could access _buffer).
sbg
Beat Küng 8 years ago
parent
commit
8bfa84f73f
  1. 10
      src/modules/logger/log_writer_file.cpp

10
src/modules/logger/log_writer_file.cpp

@ -70,6 +70,10 @@ LogWriterFile::~LogWriterFile() @@ -70,6 +70,10 @@ LogWriterFile::~LogWriterFile()
perf_free(_perf_write);
perf_free(_perf_fsync);
if (_fd >= 0) {
::close(_fd);
}
if (_buffer) {
delete[] _buffer;
}
@ -91,6 +95,8 @@ void LogWriterFile::start_log(const char *filename) @@ -91,6 +95,8 @@ void LogWriterFile::start_log(const char *filename)
if (_buffer == nullptr) {
PX4_ERR("Can't create log buffer");
::close(_fd);
_fd = -1;
_should_run = false;
return;
}
@ -174,6 +180,10 @@ void LogWriterFile::run() @@ -174,6 +180,10 @@ void LogWriterFile::run()
}
}
if (_exit_thread) {
break;
}
int poll_count = 0;
int written = 0;

Loading…
Cancel
Save