Skip to content
Snippets Groups Projects
Commit 2bc1d4a5 authored by Andrew Tridgell's avatar Andrew Tridgell
Browse files

SITL: prevent a fd leak in GPS code

parent 62f10349
No related branches found
No related tags found
No related merge requests found
...@@ -37,7 +37,7 @@ static uint8_t gps_delay; ...@@ -37,7 +37,7 @@ static uint8_t gps_delay;
// state of GPS emulation // state of GPS emulation
static struct { static struct {
/* pipe emulating UBLOX GPS serial stream */ /* pipe emulating UBLOX GPS serial stream */
int gps_fd; int gps_fd, client_fd;
uint32_t last_update; // milliseconds uint32_t last_update; // milliseconds
} gps_state; } gps_state;
...@@ -55,12 +55,16 @@ ssize_t sitl_gps_read(int fd, void *buf, size_t count) ...@@ -55,12 +55,16 @@ ssize_t sitl_gps_read(int fd, void *buf, size_t count)
int sitl_gps_pipe(void) int sitl_gps_pipe(void)
{ {
int fd[2]; int fd[2];
if (gps_state.client_fd != 0) {
return gps_state.client_fd;
}
pipe(fd); pipe(fd);
gps_state.gps_fd = fd[1]; gps_state.gps_fd = fd[1];
gps_state.client_fd = fd[0];
gps_state.last_update = millis(); gps_state.last_update = millis();
set_nonblocking(gps_state.gps_fd); set_nonblocking(gps_state.gps_fd);
set_nonblocking(fd[0]); set_nonblocking(fd[0]);
return fd[0]; return gps_state.client_fd;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment