Mercurial > hg > graal-jvmci-8
comparison src/share/vm/utilities/elfSymbolTable.cpp @ 2196:d28def44457d
7017009: Secondary out of c-heap memory error reporting out of memory
Summary: Use os::malloc() to allocate buffer to read elf symbols and check for null
Reviewed-by: zgu, phh, dsamersoff, dholmes, dcubed
author | coleenp |
---|---|
date | Thu, 03 Feb 2011 21:30:08 -0500 |
parents | 2d4762ec74af |
children | 1d1603768966 |
comparison
equal
deleted
inserted
replaced
2194:face83fc8882 | 2196:d28def44457d |
---|---|
37 m_status = Decoder::no_error; | 37 m_status = Decoder::no_error; |
38 | 38 |
39 // try to load the string table | 39 // try to load the string table |
40 long cur_offset = ftell(file); | 40 long cur_offset = ftell(file); |
41 if (cur_offset != -1) { | 41 if (cur_offset != -1) { |
42 m_symbols = (Elf_Sym*)NEW_C_HEAP_ARRAY(char, shdr.sh_size); | 42 // call malloc so we can back up if memory allocation fails. |
43 m_symbols = (Elf_Sym*)os::malloc(shdr.sh_size); | |
43 if (m_symbols) { | 44 if (m_symbols) { |
44 if (fseek(file, shdr.sh_offset, SEEK_SET) || | 45 if (fseek(file, shdr.sh_offset, SEEK_SET) || |
45 fread((void*)m_symbols, shdr.sh_size, 1, file) != 1 || | 46 fread((void*)m_symbols, shdr.sh_size, 1, file) != 1 || |
46 fseek(file, cur_offset, SEEK_SET)) { | 47 fseek(file, cur_offset, SEEK_SET)) { |
47 m_status = Decoder::file_invalid; | 48 m_status = Decoder::file_invalid; |
48 FREE_C_HEAP_ARRAY(char, m_symbols); | 49 os::free(m_symbols); |
49 m_symbols = NULL; | 50 m_symbols = NULL; |
50 } | 51 } |
51 } | 52 } |
52 if (m_status == Decoder::no_error) { | 53 if (m_status == Decoder::no_error) { |
53 memcpy(&m_shdr, &shdr, sizeof(Elf_Shdr)); | 54 memcpy(&m_shdr, &shdr, sizeof(Elf_Shdr)); |
57 } | 58 } |
58 } | 59 } |
59 | 60 |
60 ElfSymbolTable::~ElfSymbolTable() { | 61 ElfSymbolTable::~ElfSymbolTable() { |
61 if (m_symbols != NULL) { | 62 if (m_symbols != NULL) { |
62 FREE_C_HEAP_ARRAY(char, m_symbols); | 63 os::free(m_symbols); |
63 } | 64 } |
64 | 65 |
65 if (m_next != NULL) { | 66 if (m_next != NULL) { |
66 delete m_next; | 67 delete m_next; |
67 } | 68 } |