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 22:05:17 +02:00
committed by Lorenz Meier
parent 0a61e9b279
commit 5be23060e7
6 changed files with 14 additions and 6 deletions
+6 -5
View File
@@ -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;
}