mirror of
git://git.openwrt.org/openwrt/openwrt.git
synced 2024-12-28 17:42:28 +00:00
firmware-utils/mkfwimage: fix possible memory and resource leak
Add missing calls to `free` for variable `mem`. Add missing call to `fclose` for variable `f`. The same changes were made in both `mkfwimage.c` and `mkfwimage2.c`. Signed-off-by: Andrea Dalla Costa <andrea@dallacosta.me>
This commit is contained in:
parent
8e3b3152e5
commit
b886d3c8f3
@ -455,6 +455,7 @@ static int build_image(image_info_t* im)
|
|||||||
if ((f = fopen(im->outputfile, "w")) == NULL)
|
if ((f = fopen(im->outputfile, "w")) == NULL)
|
||||||
{
|
{
|
||||||
ERROR("Can not create output file: '%s'\n", im->outputfile);
|
ERROR("Can not create output file: '%s'\n", im->outputfile);
|
||||||
|
free(mem);
|
||||||
return -10;
|
return -10;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -462,6 +463,8 @@ static int build_image(image_info_t* im)
|
|||||||
{
|
{
|
||||||
ERROR("Could not write %d bytes into file: '%s'\n",
|
ERROR("Could not write %d bytes into file: '%s'\n",
|
||||||
mem_size, im->outputfile);
|
mem_size, im->outputfile);
|
||||||
|
free(mem);
|
||||||
|
fclose(f);
|
||||||
return -11;
|
return -11;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -363,12 +363,15 @@ static int build_image(void)
|
|||||||
/* write in-memory buffer into file */
|
/* write in-memory buffer into file */
|
||||||
if ((f = fopen(im.outputfile, "w")) == NULL) {
|
if ((f = fopen(im.outputfile, "w")) == NULL) {
|
||||||
ERROR("Can not create output file: '%s'\n", im.outputfile);
|
ERROR("Can not create output file: '%s'\n", im.outputfile);
|
||||||
|
free(mem);
|
||||||
return -10;
|
return -10;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fwrite(mem, mem_size, 1, f) != 1) {
|
if (fwrite(mem, mem_size, 1, f) != 1) {
|
||||||
ERROR("Could not write %d bytes into file: '%s'\n",
|
ERROR("Could not write %d bytes into file: '%s'\n",
|
||||||
mem_size, im.outputfile);
|
mem_size, im.outputfile);
|
||||||
|
free(mem);
|
||||||
|
fclose(f);
|
||||||
return -11;
|
return -11;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user