mirror of https://github.com/crash-utility/crash
Address several Coverity Scan "RESOURCE_LEAK" issues in the following
top-level source files: cmdline.c, kvmdump.c, lkcd_v8.c, xendump.c, symbols.c, unwind_x86_32_64.c, va_server.c and va_server_v1.c. (anderson@redhat.com)
This commit is contained in:
parent
3141bba98a
commit
c5f45d6cdb
|
@ -1319,8 +1319,10 @@ is_shell_script(char *s)
|
|||
if ((fd = open(s, O_RDONLY)) < 0)
|
||||
return FALSE;
|
||||
|
||||
if (isatty(fd))
|
||||
if (isatty(fd)) {
|
||||
close(fd);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (read(fd, interp, 2) != 2) {
|
||||
close(fd);
|
||||
|
|
|
@ -846,8 +846,10 @@ kvmdump_mapfile_exists(void)
|
|||
|
||||
sprintf(filename, "%s.map", pc->dumpfile);
|
||||
|
||||
if (!file_exists(filename, &stat) || !S_ISREG(stat.st_mode))
|
||||
if (!file_exists(filename, &stat) || !S_ISREG(stat.st_mode)) {
|
||||
free(filename);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (is_kvmdump_mapfile(filename)) {
|
||||
pc->kvmdump_mapfile = filename;
|
||||
|
|
|
@ -184,6 +184,7 @@ lkcd_dump_init_v8_arch(dump_header_t *dh)
|
|||
|
||||
memcpy(&dump_header_asm_v8, &arch_hdr, sizeof(dump_header_asm_t));
|
||||
|
||||
free(hdr_buf);
|
||||
return 0;
|
||||
|
||||
err:
|
||||
|
|
|
@ -3898,12 +3898,10 @@ is_bfd_format(char *filename)
|
|||
#else
|
||||
struct bfd *bfd;
|
||||
#endif
|
||||
char **matching;
|
||||
|
||||
if ((bfd = bfd_openr(filename, NULL)) == NULL)
|
||||
return FALSE;
|
||||
|
||||
if (!bfd_check_format_matches(bfd, bfd_object, &matching)) {
|
||||
if (!bfd_check_format_matches(bfd, bfd_object, NULL)) {
|
||||
bfd_close(bfd);
|
||||
return FALSE;
|
||||
}
|
||||
|
|
|
@ -819,6 +819,7 @@ try_eh_frame:
|
|||
error(WARNING, "cannot read %s data from %s\n",
|
||||
is_ehframe ? ".eh_frame" : ".debug_frame", pc->namelist);
|
||||
free(unwind_table);
|
||||
close(fd);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
10
va_server.c
10
va_server.c
|
@ -313,20 +313,27 @@ int read_map(char *crash_file)
|
|||
ret = fseek(vas_file_p, (long)0, SEEK_SET);
|
||||
if(ret == -1) {
|
||||
printf("va_server: unable to fseek, err = %d\n", ferror(vas_file_p));
|
||||
free(hdr);
|
||||
free(disk_hdr);
|
||||
return -1;
|
||||
}
|
||||
items = fread((void *)disk_hdr, 1, Page_Size, vas_file_p);
|
||||
if(items != Page_Size) {
|
||||
free(hdr);
|
||||
free(disk_hdr);
|
||||
return -1;
|
||||
}
|
||||
if(disk_hdr->magic[0] != CRASH_MAGIC) {
|
||||
free(hdr);
|
||||
free(disk_hdr);
|
||||
return -1;
|
||||
}
|
||||
ret = fseek(vas_file_p, (long)((disk_hdr->map_block) * disk_hdr->blk_size), SEEK_SET);
|
||||
|
||||
if(ret == -1) {
|
||||
printf("va_server: unable to fseek, err = %d\n", ferror(vas_file_p));
|
||||
free(hdr);
|
||||
free(disk_hdr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -338,10 +345,13 @@ int read_map(char *crash_file)
|
|||
vas_file_p);
|
||||
if(items != disk_hdr->map_blocks) {
|
||||
printf("unable to read map entries, err = %d\n", errno);
|
||||
free(hdr);
|
||||
free(disk_hdr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
vas_map_base = hdr;
|
||||
free(disk_hdr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -253,7 +253,7 @@ u_long vas_find_end_v1(void)
|
|||
}
|
||||
int read_maps_v1(char *crash_file)
|
||||
{
|
||||
int *cur_entry_p;
|
||||
int *cur_entry_p, *cp;
|
||||
int ret, items, blk_pos;
|
||||
|
||||
cur_entry_p = (int *)malloc(Page_Size);
|
||||
|
@ -266,25 +266,32 @@ int read_maps_v1(char *crash_file)
|
|||
vas_file_p = fopen(crash_file, "r");
|
||||
if(vas_file_p == (FILE *)0) {
|
||||
printf("read_maps: bad ret from fopen for %s: %s\n", crash_file, strerror(errno));
|
||||
free(cur_entry_p);
|
||||
return -1;
|
||||
}
|
||||
ret = fseek(vas_file_p, (long)0, SEEK_SET);
|
||||
if(ret == -1) {
|
||||
printf("read_maps: unable to fseek in %s, errno = %d\n", crash_file, ferror(vas_file_p));
|
||||
free(cur_entry_p);
|
||||
return -1;
|
||||
}
|
||||
items = fread((void *)cur_entry_p, 1, Page_Size, vas_file_p);
|
||||
if(items != Page_Size) {
|
||||
printf("read_maps: unable to read header from %s, errno = %d\n", crash_file, ferror(vas_file_p));
|
||||
free(cur_entry_p);
|
||||
return -1;
|
||||
}
|
||||
ret = -1;
|
||||
while ((blk_pos = *cur_entry_p++)) {
|
||||
if (read_map_v1(blk_pos))
|
||||
cp = cur_entry_p;
|
||||
while ((blk_pos = *cp++)) {
|
||||
if (read_map_v1(blk_pos)) {
|
||||
free(cur_entry_p);
|
||||
return -1;
|
||||
}
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
free(cur_entry_p);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -308,21 +315,28 @@ int read_map_v1(int blk_pos)
|
|||
ret = fseek(vas_file_p, (long)(blk_pos*Page_Size), SEEK_SET);
|
||||
if(ret == -1) {
|
||||
console("va_server: unable to fseek, err = %d\n", ferror(vas_file_p));
|
||||
free(hdr);
|
||||
free(disk_hdr);
|
||||
return -1;
|
||||
}
|
||||
items = fread((void *)disk_hdr, 1, Page_Size, vas_file_p);
|
||||
if(items != Page_Size) {
|
||||
free(hdr);
|
||||
free(disk_hdr);
|
||||
return -1;
|
||||
}
|
||||
if(disk_hdr->magic[0] != CRASH_MAGIC) {
|
||||
console("va_server: bad magic 0x%lx\n", disk_hdr->magic[0]);
|
||||
free(hdr);
|
||||
free(disk_hdr);
|
||||
return -1;
|
||||
}
|
||||
ret = fseek(vas_file_p, (long)((blk_pos + disk_hdr->map_block) * disk_hdr->blk_size), SEEK_SET);
|
||||
|
||||
if(ret == -1) {
|
||||
printf("va_server: unable to fseek, err = %d\n", ferror(vas_file_p));
|
||||
free(hdr);
|
||||
free(disk_hdr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -338,6 +352,8 @@ int read_map_v1(int blk_pos)
|
|||
vas_file_p);
|
||||
if(items != hdr->map_entries) {
|
||||
printf("unable to read map entries, err = %d\n", errno);
|
||||
free(hdr);
|
||||
free(disk_hdr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -2775,8 +2775,10 @@ xc_core_dump_elfnote(off_t sh_offset, size_t sh_size, int store)
|
|||
index += sizeof(struct elfnote) + elfnote->descsz;
|
||||
}
|
||||
|
||||
if (!store)
|
||||
if (!store) {
|
||||
free(notes_buffer);
|
||||
return;
|
||||
}
|
||||
|
||||
if (elfnote_header) {
|
||||
xd->xc_core.header.xch_magic = elfnote_header->xch_magic;
|
||||
|
@ -2798,6 +2800,7 @@ xc_core_dump_elfnote(off_t sh_offset, size_t sh_size, int store)
|
|||
xd->xc_core.format_version = format_version->version;
|
||||
}
|
||||
|
||||
free(notes_buffer);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in New Issue