Fix resource leaks identified by cppcheck

* Where possible rearrange error checks to avoid branching
* Otherwise add missing `fclose`, `close`, `px4_close` calls before return
This commit is contained in:
Peter Duerr
2017-08-07 15:31:27 +02:00
committed by Lorenz Meier
parent 0a61e9b279
commit 5be23060e7
6 changed files with 14 additions and 6 deletions
+2 -1
View File
@@ -68,13 +68,14 @@ int test_uart_loopback(int argc, char *argv[])
int stdout_fd = 1;
int uart2 = open("/dev/ttyS1", O_RDWR | O_NONBLOCK | O_NOCTTY);
int uart5 = open("/dev/ttyS2", O_RDWR | O_NONBLOCK | O_NOCTTY);
if (uart2 < 0) {
printf("ERROR opening UART2, aborting..\n");
return uart2;
}
int uart5 = open("/dev/ttyS2", O_RDWR | O_NONBLOCK | O_NOCTTY);
if (uart5 < 0) {
if (uart2 >= 0) {
close(uart2);