mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-07-13 13:50:34 +08:00
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:
committed by
Lorenz Meier
parent
0a61e9b279
commit
5be23060e7
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user