don't leave the lock held on dlopen failure..
[musl] / src / ldso / dynlink.c
index 305d70e..62dd9db 100644 (file)
@@ -509,30 +509,30 @@ void *dlopen(const char *file, int mode)
        }
 
        p = load_library(file);
-       if (!p) return 0;
+       if (!p) goto end;
 
        /* First load handling */
        if (!p->deps) {
                load_deps(p);
-               for (i=0; p->deps[i]; i++)
+               if (p->deps) for (i=0; p->deps[i]; i++)
                        if (!p->deps[i]->global)
                                p->deps[i]->global = -1;
                if (!p->global) p->global = -1;
                reloc_all(p);
-               for (i=0; p->deps[i]; i++)
+               if (p->deps) for (i=0; p->deps[i]; i++)
                        if (p->deps[i]->global < 0)
                                p->deps[i]->global = 0;
                if (p->global < 0) p->global = 0;
        }
 
        if (mode & RTLD_GLOBAL) {
-               for (i=0; p->deps[i]; i++)
+               if (p->deps) for (i=0; p->deps[i]; i++)
                        p->deps[i]->global = 1;
                p->global = 1;
        }
 
+end:
        pthread_rwlock_unlock(&lock);
-
        return p;
 }
 
@@ -541,7 +541,8 @@ static void *do_dlsym(struct dso *p, const char *s)
        size_t i;
        uint32_t h;
        Sym *sym;
-       if (p == head) return find_sym(head, s, 0);
+       if (p == head || p == RTLD_DEFAULT)
+               return find_sym(head, s, 0);
        h = hash(s);
        sym = lookup(s, h, p->syms, p->hashtab, p->strings);
        if (sym && sym->st_value && (1<<(sym->st_info&0xf) & OK_TYPES))