ruby-changes:52796
From: naruse <ko1@a...>
Date: Fri, 12 Oct 2018 08:55:55 +0900 (JST)
Subject: [ruby-changes:52796] naruse:r65010 (trunk): close dlopen-ed handle
naruse 2018-10-12 08:55:45 +0900 (Fri, 12 Oct 2018) New Revision: 65010 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=65010 Log: close dlopen-ed handle Modified files: trunk/addr2line.c Index: addr2line.c =================================================================== --- addr2line.c (revision 65009) +++ addr2line.c (revision 65010) @@ -1577,20 +1577,21 @@ fill_lines(int num_traces, void **traces https://github.com/ruby/ruby/blob/trunk/addr2line.c#L1577 char *strtab = file + dynstr_shdr->sh_offset; ElfW(Sym) *symtab = (ElfW(Sym) *)(file + dynsym_shdr->sh_offset); int symtab_count = (int)(dynsym_shdr->sh_size / sizeof(ElfW(Sym))); - for (j = 0; j < symtab_count; j++) { - ElfW(Sym) *sym = &symtab[j]; - Dl_info info; - void *h, *s; - if (ELF_ST_TYPE(sym->st_info) != STT_FUNC || sym->st_size <= 0) continue; - h = dlopen(NULL, RTLD_NOW|RTLD_LOCAL); - if (!h) continue; - s = dlsym(h, strtab + sym->st_name); - if (!s) continue; - if (dladdr(s, &info)) { - dladdr_fbase = (uintptr_t)info.dli_fbase; - break; - } - } + void *handle = dlopen(NULL, RTLD_NOW|RTLD_LOCAL); + if (handle) { + for (j = 0; j < symtab_count; j++) { + ElfW(Sym) *sym = &symtab[j]; + Dl_info info; + void *s; + if (ELF_ST_TYPE(sym->st_info) != STT_FUNC) continue; + s = dlsym(handle, strtab + sym->st_name); + if (s && dladdr(s, &info)) { + dladdr_fbase = (uintptr_t)info.dli_fbase; + break; + } + } + dlclose(handle); + } if (ehdr->e_type == ET_EXEC) { obj->base_addr = 0; } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/