Commit 1f0b0e5b authored by Philippe Teuwen's avatar Philippe Teuwen

Fix zealous double free

parent e7290de8
......@@ -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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment