Skip to content

Instantly share code, notes, and snippets.

@gaspard
Created March 25, 2012 11:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gaspard/2192960 to your computer and use it in GitHub Desktop.
Save gaspard/2192960 to your computer and use it in GitHub Desktop.
Minimal main program for bug 24945
#include <dlfcn.h>
#include <cstdio>
#include <cstring> // strerror
#include <errno.h> // errno
typedef void(*test_func)(bool);
int main() {
printf("Qt BUG related to dlclose\n=========================\n1. Program starting.\n");
printf("2. Loading dynamic library 'mod.so' linked to Qt.\n");
void *handle = dlopen("./mod.so", RTLD_NOW);
if (handle == NULL) {
printf("Library 'mod.so' not found (%s).\n", strerror(errno));
return -1;
}
printf("3. Getting 'run_test' function.\n");
test_func run_test = (test_func)dlsym(handle, "run_test");
if (run_test == NULL) {
printf("Symbol not found.\n");
return -1;
}
printf("4. Passing control to Qt.\n");
/** The bug only happens if a QApplication is effectively started.
*/
run_test(false);
printf("5. 'mod' returned.\n");
printf("6. Calling dlclose.\n");
/** This is where the bug appears.
*/
dlclose(handle);
printf("7. Program end.\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment