Fix zealous double free
This commit is contained in:
parent
e7290de83b
commit
1f0b0e5b81
2 changed files with 0 additions and 8 deletions
|
@ -79,19 +79,16 @@ uart_open(const char *pcPortName)
|
|||
sp->fd = open(pcPortName, O_RDWR | O_NOCTTY | O_NONBLOCK);
|
||||
if (sp->fd == -1) {
|
||||
uart_close_ext(sp, false);
|
||||
free(sp);
|
||||
return INVALID_SERIAL_PORT;
|
||||
}
|
||||
|
||||
if (tcgetattr(sp->fd, &sp->termios_backup) == -1) {
|
||||
uart_close_ext(sp, false);
|
||||
free(sp);
|
||||
return INVALID_SERIAL_PORT;
|
||||
}
|
||||
// Make sure the port is not claimed already
|
||||
if (sp->termios_backup.c_iflag & CCLAIMED) {
|
||||
uart_close_ext(sp, false);
|
||||
free(sp);
|
||||
return CLAIMED_SERIAL_PORT;
|
||||
}
|
||||
// Copy the old terminal info struct
|
||||
|
@ -107,7 +104,6 @@ uart_open(const char *pcPortName)
|
|||
|
||||
if (tcsetattr(sp->fd, TCSANOW, &sp->termios_new) == -1) {
|
||||
uart_close_ext(sp, true);
|
||||
free(sp);
|
||||
return INVALID_SERIAL_PORT;
|
||||
}
|
||||
return sp;
|
||||
|
|
|
@ -56,7 +56,6 @@ uart_open(const char *pcPortName)
|
|||
sp->hPort = CreateFileA(acPortName, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
|
||||
if (sp->hPort == INVALID_HANDLE_VALUE) {
|
||||
uart_close(sp);
|
||||
free(sp);
|
||||
return INVALID_SERIAL_PORT;
|
||||
}
|
||||
// Prepare the device control
|
||||
|
@ -64,13 +63,11 @@ uart_open(const char *pcPortName)
|
|||
sp->dcb.DCBlength = sizeof(DCB);
|
||||
if (!BuildCommDCBA("baud=9600 data=8 parity=N stop=1", &sp->dcb)) {
|
||||
uart_close(sp);
|
||||
free(sp);
|
||||
return INVALID_SERIAL_PORT;
|
||||
}
|
||||
// Update the active serial port
|
||||
if (!SetCommState(sp->hPort, &sp->dcb)) {
|
||||
uart_close(sp);
|
||||
free(sp);
|
||||
return INVALID_SERIAL_PORT;
|
||||
}
|
||||
|
||||
|
@ -82,7 +79,6 @@ uart_open(const char *pcPortName)
|
|||
|
||||
if (!SetCommTimeouts(sp->hPort, &sp->ct)) {
|
||||
uart_close(sp);
|
||||
free(sp);
|
||||
return INVALID_SERIAL_PORT;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue