Fix possible fd leak in peripheral_bus_uart_open 68/129868/6
authorHyeongsik Min <hyeongsik.min@samsung.com>
Thu, 18 May 2017 08:05:08 +0000 (17:05 +0900)
committerHyeongsik Min <hyeongsik.min@samsung.com>
Fri, 19 May 2017 02:06:47 +0000 (02:06 +0000)
Change-Id: Ibed226e76e6070bc45a2623d04a7bffe3dc68aa0
Signed-off-by: Hyeongsik Min <hyeongsik.min@samsung.com>
src/daemon/peripheral_bus_uart.c

index 9adac4b..db057b1 100644 (file)
@@ -121,8 +121,10 @@ int peripheral_bus_uart_open(int port, pb_uart_data_h *uart, gpointer user_data)
                return ret;
 
        uart_handle = peripheral_bus_uart_data_new(&pb_data->uart_list);
-       if (!uart_handle)
+       if (!uart_handle) {
+               uart_close(fd);
                return PERIPHERAL_ERROR_OUT_OF_MEMORY;
+       }
 
        uart_handle->fd = fd;
        uart_handle->port = port;
@@ -130,6 +132,8 @@ int peripheral_bus_uart_open(int port, pb_uart_data_h *uart, gpointer user_data)
        uart_handle->buffer = (uint8_t*)calloc(1, INITIAL_BUFFER_SIZE);
        if (!uart_handle->buffer) {
                _E("Failed to allocate buffer");
+               peripheral_bus_uart_data_free(uart_handle, &pb_data->uart_list);
+               uart_close(fd);
                return  PERIPHERAL_ERROR_OUT_OF_MEMORY;
        }