mirror of
https://github.com/openwrt/openwrt.git
synced 2025-02-06 11:09:31 +00:00
firmware-utils/hcsmakeimage: fix possible memory leak and resource leaks
Add missing calls to `free` for variable `filebuffer`. Add missing calls to `fclose` for variables `fd` and `fd_out`. Signed-off-by: Andrea Dalla Costa <andrea@dallacosta.me>
This commit is contained in:
parent
4a77a060ab
commit
d64b20da21
@ -183,6 +183,7 @@ int main ( int argc, char** argv )
|
|||||||
char* filebuffer = malloc ( buf.st_size+10 );
|
char* filebuffer = malloc ( buf.st_size+10 );
|
||||||
FILE* fd = fopen ( input,"r" );
|
FILE* fd = fopen ( input,"r" );
|
||||||
fread ( filebuffer, 1, buf.st_size,fd );
|
fread ( filebuffer, 1, buf.st_size,fd );
|
||||||
|
fclose (fd);
|
||||||
if (!output)
|
if (!output)
|
||||||
{
|
{
|
||||||
output = malloc(strlen(input+5));
|
output = malloc(strlen(input+5));
|
||||||
@ -194,10 +195,13 @@ int main ( int argc, char** argv )
|
|||||||
if (!fd_out)
|
if (!fd_out)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Failed to open output file: %s\n", output);
|
fprintf(stderr, "Failed to open output file: %s\n", output);
|
||||||
|
free(filebuffer);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
fwrite ( head,1,sizeof ( ldr_header_t ),fd_out );
|
fwrite ( head,1,sizeof ( ldr_header_t ),fd_out );
|
||||||
fwrite ( filebuffer,1,buf.st_size,fd_out );
|
fwrite ( filebuffer,1,buf.st_size,fd_out );
|
||||||
printf("Firmware image %s is ready\n", output);
|
printf("Firmware image %s is ready\n", output);
|
||||||
|
free(filebuffer);
|
||||||
|
fclose(fd_out);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user