Ensure UART file descriptors are valid before using them in uart_close ().
The uart_open() function may call uart_close() with a 'serial_port' structure with an invalid member 'fd' if the port was not opened successfully. The call to uart_close() was kept for consistency with the rest of the function because uart_close() is also in charge of freeing 'serial_port'.
This commit is contained in:
parent
3f8068b760
commit
e92de4d49e
1 changed files with 7 additions and 3 deletions
|
@ -170,8 +170,10 @@ uint32_t uart_get_speed(const serial_port sp)
|
|||
|
||||
void uart_close(const serial_port sp)
|
||||
{
|
||||
if (((serial_port_unix*)sp)->fd >= 0) {
|
||||
tcsetattr(((serial_port_unix*)sp)->fd,TCSANOW,&((serial_port_unix*)sp)->tiOld);
|
||||
close(((serial_port_unix*)sp)->fd);
|
||||
}
|
||||
free(sp);
|
||||
}
|
||||
|
||||
|
@ -333,7 +335,9 @@ serial_port uart_open(const char* pcPortName)
|
|||
|
||||
void uart_close(const serial_port sp)
|
||||
{
|
||||
if (((serial_port_windows*)sp)->hPort != INVALID_HANDLE_VALUE) {
|
||||
CloseHandle(((serial_port_windows*)sp)->hPort);
|
||||
}
|
||||
free(sp);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue