mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-11-03 04:01:36 +08:00
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:
@@ -70,6 +70,10 @@ LogWriterFile::~LogWriterFile()
|
|||||||
perf_free(_perf_write);
|
perf_free(_perf_write);
|
||||||
perf_free(_perf_fsync);
|
perf_free(_perf_fsync);
|
||||||
|
|
||||||
|
if (_fd >= 0) {
|
||||||
|
::close(_fd);
|
||||||
|
}
|
||||||
|
|
||||||
if (_buffer) {
|
if (_buffer) {
|
||||||
delete[] _buffer;
|
delete[] _buffer;
|
||||||
}
|
}
|
||||||
@@ -91,6 +95,8 @@ void LogWriterFile::start_log(const char *filename)
|
|||||||
|
|
||||||
if (_buffer == nullptr) {
|
if (_buffer == nullptr) {
|
||||||
PX4_ERR("Can't create log buffer");
|
PX4_ERR("Can't create log buffer");
|
||||||
|
::close(_fd);
|
||||||
|
_fd = -1;
|
||||||
_should_run = false;
|
_should_run = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -174,6 +180,10 @@ void LogWriterFile::run()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_exit_thread) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
int poll_count = 0;
|
int poll_count = 0;
|
||||||
int written = 0;
|
int written = 0;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user