firmware-utils: fix possible memory leak and resource leak
Add missing calls to `free` for variable `buffer`. This could lead to a memory leak. Add missing call to `close` for file pointer `fdin`. This could lead to a resource leak. Signed-off-by: Andrea Dalla Costa <andrea@dallacosta.me>
This commit is contained in:
parent
402b362db4
commit
0ae0f48cec
|
|
@ -168,11 +168,14 @@ int main(int argc, char **argv)
|
||||||
fdin = open(pathin, O_RDONLY);
|
fdin = open(pathin, O_RDONLY);
|
||||||
if (!fdin) {
|
if (!fdin) {
|
||||||
printf("ERROR: could not open input file\n");
|
printf("ERROR: could not open input file\n");
|
||||||
|
free(buffer);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
bytes = read(fdin, buffer + HEADER_SIZE, filesize);
|
bytes = read(fdin, buffer + HEADER_SIZE, filesize);
|
||||||
if (bytes < filesize) {
|
if (bytes < filesize) {
|
||||||
printf("ERROR: could not read entire file\n");
|
printf("ERROR: could not read entire file\n");
|
||||||
|
free(buffer);
|
||||||
|
close(fdin);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
close(fdin);
|
close(fdin);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue