firmware-utils/mksenaofw: fix possible memory leak
This commit is contained in:
parent
49a5fd80a0
commit
d483f93a5e
@ -86,6 +86,8 @@ void write_img(unsigned char* img, const char *fname)
|
||||
fclose(fp);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
|
||||
@ -104,6 +106,8 @@ void write_rootfs(unsigned char* img, const char *fname)
|
||||
fclose(fp);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
|
||||
@ -122,6 +126,8 @@ void write_kernel(unsigned char* img, const char *fname)
|
||||
fclose(fp);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -168,11 +168,14 @@ int main(int argc, char **argv)
|
||||
fdin = open(pathin, O_RDONLY);
|
||||
if (!fdin) {
|
||||
printf("ERROR: could not open input file\n");
|
||||
free(buffer);
|
||||
return 0;
|
||||
}
|
||||
bytes = read(fdin, buffer + HEADER_SIZE, filesize);
|
||||
if (bytes < filesize) {
|
||||
printf("ERROR: could not read entire file\n");
|
||||
free(buffer);
|
||||
close(fdin);
|
||||
return 0;
|
||||
}
|
||||
close(fdin);
|
||||
|
||||
@ -231,6 +231,7 @@ main (int argc, char * argv[])
|
||||
if (fs_file) {
|
||||
fs_fp = fopen (fs_file, "r");
|
||||
if (!fs_fp) {
|
||||
fclose(kern_fp);
|
||||
fatal_error (errno, "Cannot open %s", fs_file);
|
||||
}
|
||||
}
|
||||
@ -238,6 +239,10 @@ main (int argc, char * argv[])
|
||||
/* Open the output file */
|
||||
out_fp = fopen (output_file, "w+");
|
||||
if (!out_fp) {
|
||||
fclose(kern_fp);
|
||||
if (fs_fp) {
|
||||
fclose(fs_fp);
|
||||
}
|
||||
fatal_error (errno, "Cannot open %s", output_file);
|
||||
}
|
||||
|
||||
@ -285,6 +290,7 @@ main (int argc, char * argv[])
|
||||
netgear_checksum_add (&chk_part, (unsigned char *)buf, len);
|
||||
netgear_checksum_add (&chk_whole, (unsigned char *)buf, len);
|
||||
}
|
||||
fclose(kern_fp);
|
||||
hdr->kernel_chksum = netgear_checksum_fini (&chk_part);
|
||||
message (" Kernel Len: %u", hdr->kernel_len);
|
||||
message ("Kernel Checksum: 0x%08x", hdr->kernel_chksum);
|
||||
@ -306,6 +312,7 @@ main (int argc, char * argv[])
|
||||
netgear_checksum_add (&chk_part, (unsigned char *)buf, len);
|
||||
netgear_checksum_add (&chk_whole, (unsigned char *)buf, len);
|
||||
}
|
||||
fclose(fs_fp);
|
||||
hdr->rootfs_chksum = (netgear_checksum_fini (&chk_part));
|
||||
message (" Rootfs Len: %u", hdr->rootfs_len);
|
||||
message ("Rootfs Checksum: 0x%08x", hdr->rootfs_chksum);
|
||||
@ -336,6 +343,7 @@ main (int argc, char * argv[])
|
||||
}
|
||||
|
||||
/* Success */
|
||||
fclose(out_fp);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@ -110,6 +110,15 @@ struct fw_info fw_info[] = {
|
||||
},
|
||||
.sign = false,
|
||||
},
|
||||
{
|
||||
.name = "SW",
|
||||
.fw_layout = {
|
||||
.kern_start = 0x9f050000,
|
||||
.kern_entry = 0x80002000,
|
||||
.firmware_max_length= 0x00760000,
|
||||
},
|
||||
.sign = false,
|
||||
},
|
||||
{
|
||||
.name = "UBDEV01",
|
||||
.fw_layout = {
|
||||
@ -128,6 +137,15 @@ struct fw_info fw_info[] = {
|
||||
},
|
||||
.sign = true,
|
||||
},
|
||||
{
|
||||
.name = "ACB-ISP",
|
||||
.fw_layout = {
|
||||
.kern_start = 0x9f050000,
|
||||
.kern_entry = 0x80002000,
|
||||
.firmware_max_length= 0x00F60000,
|
||||
},
|
||||
.sign = true,
|
||||
},
|
||||
{
|
||||
.name = "",
|
||||
},
|
||||
@ -437,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;
|
||||
}
|
||||
|
||||
@ -444,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;
|
||||
}
|
||||
|
||||
|
||||
@ -363,12 +363,15 @@ static int build_image(void)
|
||||
/* write in-memory buffer into file */
|
||||
if ((f = fopen(im.outputfile, "w")) == NULL) {
|
||||
ERROR("Can not create output file: '%s'\n", im.outputfile);
|
||||
free(mem);
|
||||
return -10;
|
||||
}
|
||||
|
||||
if (fwrite(mem, mem_size, 1, f) != 1) {
|
||||
ERROR("Could not write %d bytes into file: '%s'\n",
|
||||
mem_size, im.outputfile);
|
||||
free(mem);
|
||||
fclose(f);
|
||||
return -11;
|
||||
}
|
||||
|
||||
|
||||
@ -316,10 +316,12 @@ int decode_image(const char *input_file_name, const char *output_file_name)
|
||||
if (fread(pmodel, 1, cw_header.model_size, fp_input) !=
|
||||
cw_header.model_size) {
|
||||
fprintf(stderr, "Incorrect header size reading model name!!");
|
||||
free(pmodel);
|
||||
fclose(fp_input);
|
||||
fclose(fp_output);
|
||||
return -1;
|
||||
}
|
||||
free(pmodel);
|
||||
} else {
|
||||
fprintf(stderr, "Incorrect header size reading model name!!");
|
||||
fclose(fp_input);
|
||||
|
||||
@ -225,6 +225,7 @@ int main(int argc, char* argv[], char* env[])
|
||||
if(fwrite((void*)buf,1,padding,nsp_image)!=padding) {
|
||||
printf("ERROR: can't write to %s.\n", filen_out);
|
||||
free(buf);
|
||||
fclose(nsp_image);
|
||||
return -1;
|
||||
}
|
||||
free(buf);
|
||||
|
||||
@ -144,6 +144,12 @@ static struct flash_layout layouts[] = {
|
||||
.kernel_la = 0x80060000,
|
||||
.kernel_ep = 0x80060000,
|
||||
.rootfs_ofs = 0x100000,
|
||||
}, {
|
||||
.id = "8Mmtk",
|
||||
.fw_max_len = 0x7c0000,
|
||||
.kernel_la = 0x80000000,
|
||||
.kernel_ep = 0x8000c310,
|
||||
.rootfs_ofs = 0x100000,
|
||||
}, {
|
||||
.id = "16M",
|
||||
.fw_max_len = 0xf80000,
|
||||
|
||||
@ -891,7 +891,7 @@ static struct device_info boards[] = {
|
||||
"{product_name:Archer C6,product_ver:2.0.0,special_id:52550000}\r\n"
|
||||
"{product_name:Archer C6,product_ver:2.0.0,special_id:4A500000}\r\n",
|
||||
.support_trail = '\x00',
|
||||
.soft_ver = "soft_ver:1.0.0\n",
|
||||
.soft_ver = "soft_ver:1.1.1\n",
|
||||
|
||||
.partitions = {
|
||||
{"fs-uboot", 0x00000, 0x20000},
|
||||
@ -1437,6 +1437,42 @@ static struct device_info boards[] = {
|
||||
.last_sysupgrade_partition = "file-system",
|
||||
},
|
||||
|
||||
/** Firmware layout for the RE305 v1 */
|
||||
{
|
||||
.id = "RE305-V1",
|
||||
.vendor = "",
|
||||
.support_list =
|
||||
"SupportList:\n"
|
||||
"{product_name:RE305,product_ver:1.0.0,special_id:45550000}\n"
|
||||
"{product_name:RE305,product_ver:1.0.0,special_id:55530000}\n"
|
||||
"{product_name:RE305,product_ver:1.0.0,special_id:4a500000}\n"
|
||||
"{product_name:RE305,product_ver:1.0.0,special_id:42520000}\n"
|
||||
"{product_name:RE305,product_ver:1.0.0,special_id:4b520000}\n"
|
||||
"{product_name:RE305,product_ver:1.0.0,special_id:41550000}\n"
|
||||
"{product_name:RE305,product_ver:1.0.0,special_id:43410000}\n",
|
||||
.support_trail = '\x00',
|
||||
.soft_ver = NULL,
|
||||
|
||||
.partitions = {
|
||||
{"fs-uboot", 0x00000, 0x20000},
|
||||
{"firmware", 0x20000, 0x5e0000},
|
||||
{"partition-table", 0x600000, 0x02000},
|
||||
{"default-mac", 0x610000, 0x00020},
|
||||
{"pin", 0x610100, 0x00020},
|
||||
{"product-info", 0x611100, 0x01000},
|
||||
{"soft-version", 0x620000, 0x01000},
|
||||
{"support-list", 0x621000, 0x01000},
|
||||
{"profile", 0x622000, 0x08000},
|
||||
{"user-config", 0x630000, 0x10000},
|
||||
{"default-config", 0x640000, 0x10000},
|
||||
{"radio", 0x7f0000, 0x10000},
|
||||
{NULL, 0, 0}
|
||||
},
|
||||
|
||||
.first_sysupgrade_partition = "os-image",
|
||||
.last_sysupgrade_partition = "file-system"
|
||||
},
|
||||
|
||||
/** Firmware layout for the RE350 v1 */
|
||||
{
|
||||
.id = "RE350-V1",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user