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).
This commit is contained in:
Beat Küng
2017-05-04 08:44:11 +02:00
parent 50740ef813
commit 8bfa84f73f
+10
View File
@@ -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)
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()
}
}
if (_exit_thread) {
break;
}
int poll_count = 0;
int written = 0;