commit c5f45d6cdbe7f01314857a75b2feef25b22adaaa
Author: Dave Anderson <anderson@redhat.com>
Date: Thu Oct 11 13:28:39 2018 -0400
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)
diff --git a/cmdline.c b/cmdline.c
index c0a9f4f..cf3e150 100644
--- a/cmdline.c
+++ b/cmdline.c
@@ -1318,8 +1318,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);
diff --git a/kvmdump.c b/kvmdump.c
index 622619c..4db96bd 100644
--- a/kvmdump.c
+++ b/kvmdump.c
@@ -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;
diff --git a/lkcd_v8.c b/lkcd_v8.c
index 1322250..3b355e0 100644
--- a/lkcd_v8.c
+++ b/lkcd_v8.c
@@ -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:
diff --git a/symbols.c b/symbols.c
index b54b8c0..fb9cd1b 100644
--- a/symbols.c
+++ b/symbols.c
@@ -3862,12 +3862,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;
}
diff --git a/unwind_x86_32_64.c b/unwind_x86_32_64.c
index c62f92f..c7c30d6 100644
--- a/unwind_x86_32_64.c
+++ b/unwind_x86_32_64.c
@@ -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;
}
diff --git a/va_server.c b/va_server.c
index d96287a..96c2b5c 100644
--- a/va_server.c
+++ b/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;
}
diff --git a/va_server_v1.c b/va_server_v1.c
index 1924946..88a2a5a 100644
--- a/va_server_v1.c
+++ b/va_server_v1.c
@@ -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;
}
diff --git a/xendump.c b/xendump.c
index 4bd59b5..70cf261 100644
--- a/xendump.c
+++ b/xendump.c
@@ -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);
}
/*