From: Hyeongsik Min Date: Thu, 18 May 2017 08:05:08 +0000 (+0900) Subject: Fix possible fd leak in peripheral_bus_uart_open X-Git-Tag: accepted/tizen/unified/20170602.054035~11 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F68%2F129868%2F6;p=platform%2Fcore%2Fsystem%2Fperipheral-bus.git Fix possible fd leak in peripheral_bus_uart_open Change-Id: Ibed226e76e6070bc45a2623d04a7bffe3dc68aa0 Signed-off-by: Hyeongsik Min --- diff --git a/src/daemon/peripheral_bus_uart.c b/src/daemon/peripheral_bus_uart.c index 9adac4b..db057b1 100644 --- a/src/daemon/peripheral_bus_uart.c +++ b/src/daemon/peripheral_bus_uart.c @@ -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; }