Mercurial > hg > truffle
diff agent/src/os/bsd/symtab.c @ 4006:436b4a3231bf
7098194: integrate macosx-port changes
Summary: Integrate bsd-port/hotspot and macosx-port/hotspot changes as of 2011.09.29.
Reviewed-by: kvn, dholmes, never, phh
Contributed-by: Christos Zoulas <christos@zoulas.com>, Greg Lewis <glewis@eyesbeyond.com>, Kurt Miller <kurt@intricatesoftware.com>, Alexander Strange <astrange@apple.com>, Mike Swingler <swingler@apple.com>, Roger Hoover <rhoover@apple.com>, Victor Hernandez <vhernandez@apple.com>, Pratik Solanki <psolanki@apple.com>
author | dcubed |
---|---|
date | Thu, 13 Oct 2011 09:35:42 -0700 |
parents | f08d439fab8c |
children | 39432a1cefdd |
line wrap: on
line diff
--- a/agent/src/os/bsd/symtab.c Mon Oct 10 21:01:36 2011 -0400 +++ b/agent/src/os/bsd/symtab.c Thu Oct 13 09:35:42 2011 -0700 @@ -116,7 +116,7 @@ if (shdr->sh_type == symsection) { ELF_SYM *syms; - int j, n, rslt; + int j, n; size_t size; // FIXME: there could be multiple data buffers associated with the @@ -138,6 +138,8 @@ // manipulate the hash table. symtab->hash_table = dbopen(NULL, O_CREAT | O_RDWR, 0600, DB_HASH, NULL); // guarantee(symtab->hash_table, "unexpected failure: dbopen"); + if (symtab->hash_table == NULL) + goto bad; // shdr->sh_link points to the section that contains the actual strings // for symbol names. the st_name field in ELF_SYM is just the @@ -145,11 +147,15 @@ // strings will not be destroyed by elf_end. size = scn_cache[shdr->sh_link].c_shdr->sh_size; symtab->strs = malloc(size); + if (symtab->strs == NULL) + goto bad; memcpy(symtab->strs, scn_cache[shdr->sh_link].c_data, size); // allocate memory for storing symbol offset and size; symtab->num_symbols = n; symtab->symbols = calloc(n , sizeof(*symtab->symbols)); + if (symtab->symbols == NULL) + goto bad; // copy symbols info our symtab and enter them info the hash table for (j = 0; j < n; j++, syms++) { @@ -175,6 +181,11 @@ } } } + goto quit; + +bad: + destroy_symtab(symtab); + symtab = NULL; quit: if (shbuf) free(shbuf); @@ -195,7 +206,7 @@ if (symtab->strs) free(symtab->strs); if (symtab->symbols) free(symtab->symbols); if (symtab->hash_table) { - symtab->hash_table->close(symtab->hash_table); + (*symtab->hash_table->close)(symtab->hash_table); } free(symtab); } @@ -219,7 +230,6 @@ return rslt; } -quit: return 0; } @@ -228,12 +238,12 @@ int n = 0; if (!symtab) return NULL; for (; n < symtab->num_symbols; n++) { - struct elf_symbol* sym = &(symtab->symbols[n]); - if (sym->name != NULL && - offset >= sym->offset && offset < sym->offset + sym->size) { - if (poffset) *poffset = (offset - sym->offset); - return sym->name; - } + struct elf_symbol* sym = &(symtab->symbols[n]); + if (sym->name != NULL && + offset >= sym->offset && offset < sym->offset + sym->size) { + if (poffset) *poffset = (offset - sym->offset); + return sym->name; + } } return NULL; }