From 1f0b0e5b81e5895c6dcfda8a685293511b895a90 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sat, 2 Mar 2013 12:26:24 +0100 Subject: [PATCH] Fix zealous double free --- libnfc/buses/uart_posix.c | 4 ---- libnfc/buses/uart_win32.c | 4 ---- 2 files changed, 8 deletions(-) diff --git a/libnfc/buses/uart_posix.c b/libnfc/buses/uart_posix.c index 84bf5b4..7b687c1 100644 --- a/libnfc/buses/uart_posix.c +++ b/libnfc/buses/uart_posix.c @@ -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; diff --git a/libnfc/buses/uart_win32.c b/libnfc/buses/uart_win32.c index 82c92b1..f14e28d 100644 --- a/libnfc/buses/uart_win32.c +++ b/libnfc/buses/uart_win32.c @@ -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; }