Fix zealous double free

This commit is contained in:
Philippe Teuwen 2013-03-02 12:26:24 +01:00
parent e7290de83b
commit 1f0b0e5b81
2 changed files with 0 additions and 8 deletions

View file

@ -79,19 +79,16 @@ uart_open(const char *pcPortName)
sp->fd = open(pcPortName, O_RDWR | O_NOCTTY | O_NONBLOCK); sp->fd = open(pcPortName, O_RDWR | O_NOCTTY | O_NONBLOCK);
if (sp->fd == -1) { if (sp->fd == -1) {
uart_close_ext(sp, false); uart_close_ext(sp, false);
free(sp);
return INVALID_SERIAL_PORT; return INVALID_SERIAL_PORT;
} }
if (tcgetattr(sp->fd, &sp->termios_backup) == -1) { if (tcgetattr(sp->fd, &sp->termios_backup) == -1) {
uart_close_ext(sp, false); uart_close_ext(sp, false);
free(sp);
return INVALID_SERIAL_PORT; return INVALID_SERIAL_PORT;
} }
// Make sure the port is not claimed already // Make sure the port is not claimed already
if (sp->termios_backup.c_iflag & CCLAIMED) { if (sp->termios_backup.c_iflag & CCLAIMED) {
uart_close_ext(sp, false); uart_close_ext(sp, false);
free(sp);
return CLAIMED_SERIAL_PORT; return CLAIMED_SERIAL_PORT;
} }
// Copy the old terminal info struct // Copy the old terminal info struct
@ -107,7 +104,6 @@ uart_open(const char *pcPortName)
if (tcsetattr(sp->fd, TCSANOW, &sp->termios_new) == -1) { if (tcsetattr(sp->fd, TCSANOW, &sp->termios_new) == -1) {
uart_close_ext(sp, true); uart_close_ext(sp, true);
free(sp);
return INVALID_SERIAL_PORT; return INVALID_SERIAL_PORT;
} }
return sp; return sp;

View file

@ -56,7 +56,6 @@ uart_open(const char *pcPortName)
sp->hPort = CreateFileA(acPortName, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); sp->hPort = CreateFileA(acPortName, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
if (sp->hPort == INVALID_HANDLE_VALUE) { if (sp->hPort == INVALID_HANDLE_VALUE) {
uart_close(sp); uart_close(sp);
free(sp);
return INVALID_SERIAL_PORT; return INVALID_SERIAL_PORT;
} }
// Prepare the device control // Prepare the device control
@ -64,13 +63,11 @@ uart_open(const char *pcPortName)
sp->dcb.DCBlength = sizeof(DCB); sp->dcb.DCBlength = sizeof(DCB);
if (!BuildCommDCBA("baud=9600 data=8 parity=N stop=1", &sp->dcb)) { if (!BuildCommDCBA("baud=9600 data=8 parity=N stop=1", &sp->dcb)) {
uart_close(sp); uart_close(sp);
free(sp);
return INVALID_SERIAL_PORT; return INVALID_SERIAL_PORT;
} }
// Update the active serial port // Update the active serial port
if (!SetCommState(sp->hPort, &sp->dcb)) { if (!SetCommState(sp->hPort, &sp->dcb)) {
uart_close(sp); uart_close(sp);
free(sp);
return INVALID_SERIAL_PORT; return INVALID_SERIAL_PORT;
} }
@ -82,7 +79,6 @@ uart_open(const char *pcPortName)
if (!SetCommTimeouts(sp->hPort, &sp->ct)) { if (!SetCommTimeouts(sp->hPort, &sp->ct)) {
uart_close(sp); uart_close(sp);
free(sp);
return INVALID_SERIAL_PORT; return INVALID_SERIAL_PORT;
} }