1

I'm opening a dynamic library with a call to dlopen():

void *handle = dlopen("mylib.so", RTLD_LAZY | RTLD_GLOBAL);
if (!handle) 
    printf("%s", dlerror());

When this is called for a library which has an undefined symbol, the returned handle is NULL and I get the following printed in TTY:

libmylib.so: undefined symbol: < the_symbol_name >

This is fine. But when I call this same code for the same library name for the second time, the returned handle is NOT NULL, and I get a crash when dereferencing it.

From the docs:

If dlopen() fails for any reason, it returns NULL.

So why isn't NULL returned the second time?

user3132457
  • 789
  • 2
  • 11
  • 29
  • 1
    Sounds like this: https://stackoverflow.com/questions/6591389/dlopen-works-second-time-on-bad-shared-library-on-ubuntu-11-04-does-the-right-t?rq=1 – viraptor Dec 03 '19 at 04:58
  • @viraptor The link lacks a good answer though. – yugr Dec 03 '19 at 08:38
  • if you do get a stacktrace that ends in libc and have a minimal example, it could be worth reporting a bug upstream (glibc I assume?) – viraptor Dec 03 '19 at 10:01

0 Answers0