diff --git a/src/platforms/posix/drivers/tonealrmsim/tone_alarm.cpp b/src/platforms/posix/drivers/tonealrmsim/tone_alarm.cpp index d33409dba1..a491e98739 100644 --- a/src/platforms/posix/drivers/tonealrmsim/tone_alarm.cpp +++ b/src/platforms/posix/drivers/tonealrmsim/tone_alarm.cpp @@ -851,6 +851,7 @@ tone_alarm_main(int argc, char *argv[]) if (buffer == nullptr) { PX4_WARN("not enough memory memory"); + fclose(fd); return 1; } diff --git a/src/systemcmds/sd_bench/sd_bench.c b/src/systemcmds/sd_bench/sd_bench.c index f1be95ee52..0e490f1c41 100644 --- a/src/systemcmds/sd_bench/sd_bench.c +++ b/src/systemcmds/sd_bench/sd_bench.c @@ -118,6 +118,11 @@ sd_bench_main(int argc, char *argv[]) } } + if (block_size <= 0 || num_runs <= 0) { + PX4_ERR("invalid argument"); + return -1; + } + int bench_fd = open(BENCHMARK_FILE, O_CREAT | O_WRONLY | O_TRUNC, PX4_O_MODE_666); if (bench_fd < 0) { @@ -125,16 +130,12 @@ sd_bench_main(int argc, char *argv[]) return -1; } - if (block_size <= 0 || num_runs <= 0) { - PX4_ERR("invalid argument"); - return -1; - } - //create some data block uint8_t *block = (uint8_t *)malloc(block_size); if (!block) { PX4_ERR("Failed to allocate memory block"); + close(bench_fd); return -1; } diff --git a/src/systemcmds/tests/test_file2.c b/src/systemcmds/tests/test_file2.c index 700803f9b5..b5339d79bd 100644 --- a/src/systemcmds/tests/test_file2.c +++ b/src/systemcmds/tests/test_file2.c @@ -133,12 +133,14 @@ static void test_corruption(const char *filename, uint32_t write_chunk, uint32_t if (read(fd, buffer, sizeof(buffer)) != (int)sizeof(buffer)) { printf("read failed at offset %u\n", ofs); + close(fd); return; } for (uint16_t j = 0; j < write_chunk; j++) { if (buffer[j] != get_value(ofs)) { printf("corruption at ofs=%u got %u\n", ofs, buffer[j]); + close(fd); return; } diff --git a/src/systemcmds/tests/test_mount.c b/src/systemcmds/tests/test_mount.c index 9ad674a433..9a98ae5896 100644 --- a/src/systemcmds/tests/test_mount.c +++ b/src/systemcmds/tests/test_mount.c @@ -158,6 +158,7 @@ test_mount(int argc, char *argv[]) } if (it_left_abort == 0) { + px4_close(cmd_fd); (void)unlink(cmd_filename); return 0; } diff --git a/src/systemcmds/tests/test_ppm_loopback.c b/src/systemcmds/tests/test_ppm_loopback.c index f99e5c30f1..445da47888 100644 --- a/src/systemcmds/tests/test_ppm_loopback.c +++ b/src/systemcmds/tests/test_ppm_loopback.c @@ -79,6 +79,8 @@ int test_ppm_loopback(int argc, char *argv[]) if (result != OK) { warnx("PWM_SERVO_GET_COUNT"); + + (void)close(servo_fd); return ERROR; } diff --git a/src/systemcmds/tests/test_uart_loopback.c b/src/systemcmds/tests/test_uart_loopback.c index d7df51517b..046d51ecaa 100644 --- a/src/systemcmds/tests/test_uart_loopback.c +++ b/src/systemcmds/tests/test_uart_loopback.c @@ -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);