util/cbfstool: avoid memleaks and off-by-ones
Change-Id: Iac136a5dfe76f21aa7c0d5ee4e974e50b955403b Signed-off-by: Patrick Georgi <pgeorgi@chromium.org> Found-by: scan-build 3.8 Reviewed-on: https://review.coreboot.org/18134 Tested-by: build bot (Jenkins) Reviewed-by: Nico Huber <nico.h@gmx.de>
This commit is contained in:
parent
1dfc0a64d4
commit
dce629b2f8
|
@ -1150,13 +1150,22 @@ static int cbfs_payload_make_elf(struct buffer *buff, uint32_t arch)
|
||||||
segs[i].len);
|
segs[i].len);
|
||||||
} else if (segs[i].type == PAYLOAD_SEGMENT_ENTRY) {
|
} else if (segs[i].type == PAYLOAD_SEGMENT_ENTRY) {
|
||||||
break;
|
break;
|
||||||
|
} else {
|
||||||
|
ERROR("unknown ELF segment type\n");
|
||||||
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!name) {
|
||||||
|
ERROR("out of memory\n");
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
if (elf_writer_add_section(ew, &shdr, &tbuff, name)) {
|
if (elf_writer_add_section(ew, &shdr, &tbuff, name)) {
|
||||||
ERROR("Unable to add ELF section: %s\n", name);
|
ERROR("Unable to add ELF section: %s\n", name);
|
||||||
|
free(name);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
free(name);
|
||||||
|
|
||||||
if (empty_sz != 0) {
|
if (empty_sz != 0) {
|
||||||
struct buffer b;
|
struct buffer b;
|
||||||
|
@ -1168,10 +1177,16 @@ static int cbfs_payload_make_elf(struct buffer *buff, uint32_t arch)
|
||||||
shdr.sh_addr = segs[i].load_addr + segs[i].len;
|
shdr.sh_addr = segs[i].load_addr + segs[i].len;
|
||||||
shdr.sh_size = empty_sz;
|
shdr.sh_size = empty_sz;
|
||||||
name = strdup(".empty");
|
name = strdup(".empty");
|
||||||
if (elf_writer_add_section(ew, &shdr, &b, name)) {
|
if (!name) {
|
||||||
ERROR("Unable to add ELF section: %s\n", name);
|
ERROR("out of memory\n");
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
if (elf_writer_add_section(ew, &shdr, &b, name)) {
|
||||||
|
ERROR("Unable to add ELF section: %s\n", name);
|
||||||
|
free(name);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
free(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,6 +49,7 @@ int benchmark()
|
||||||
}
|
}
|
||||||
char *compressed_data = malloc(bufsize);
|
char *compressed_data = malloc(bufsize);
|
||||||
if (!compressed_data) {
|
if (!compressed_data) {
|
||||||
|
free(data);
|
||||||
fprintf(stderr, "out of memory\n");
|
fprintf(stderr, "out of memory\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -64,6 +65,8 @@ int benchmark()
|
||||||
comp_func_ptr comp = compression_function(algo->type);
|
comp_func_ptr comp = compression_function(algo->type);
|
||||||
if (comp == NULL) {
|
if (comp == NULL) {
|
||||||
printf("no handler associated with algorithm\n");
|
printf("no handler associated with algorithm\n");
|
||||||
|
free(data);
|
||||||
|
free(compressed_data);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,6 +83,8 @@ int benchmark()
|
||||||
bufsize, outsize,
|
bufsize, outsize,
|
||||||
t_e.tv_sec - t_s.tv_sec);
|
t_e.tv_sec - t_s.tv_sec);
|
||||||
}
|
}
|
||||||
|
free(data);
|
||||||
|
free(compressed_data);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -289,7 +289,7 @@ static void print_with_prefix(const struct flashmap_descriptor *tree,
|
||||||
if (tree->list_len) {
|
if (tree->list_len) {
|
||||||
puts(":");
|
puts(":");
|
||||||
|
|
||||||
char child_prefix[strlen(pre) + 1];
|
char child_prefix[strlen(pre) + 2];
|
||||||
strcpy(child_prefix, pre);
|
strcpy(child_prefix, pre);
|
||||||
strcat(child_prefix, "\t");
|
strcat(child_prefix, "\t");
|
||||||
fmd_foreach_child(each, tree)
|
fmd_foreach_child(each, tree)
|
||||||
|
|
Loading…
Reference in New Issue