firmware-utils/mkfwimage: fix possible memory and resource leak
[openwrt/staging/mkresin.git] / tools / firmware-utils / src / mkfwimage.c
index d0dca040cdaee4d71a39ada82b8242ba08a7c7e8..9e6d8f5b9ab4b62305ba10e6c670a53ee8e7b2ee 100644 (file)
@@ -455,6 +455,7 @@ static int build_image(image_info_t* im)
        if ((f = fopen(im->outputfile, "w")) == NULL)
        {
                ERROR("Can not create output file: '%s'\n", im->outputfile);
+               free(mem);
                return -10;
        }
 
@@ -462,6 +463,8 @@ static int build_image(image_info_t* im)
        {
                ERROR("Could not write %d bytes into file: '%s'\n",
                                mem_size, im->outputfile);
+               free(mem);
+               fclose(f);
                return -11;
        }