Skip to content

Commit

Permalink
Show dlerror() only if it's actually non-NULL (JuliaLang#44856)
Browse files Browse the repository at this point in the history
This prevents a segmentation fault when showing an error message when libjulia
can't be loaded.
  • Loading branch information
giordano authored Apr 5, 2022
1 parent 3fb132f commit 0a7d5d1
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions cli/loader_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ static void * load_library(const char * rel_path, const char * src_dir, int err)
wchar_to_utf8(wmsg, err, 255);
jl_loader_print_stderr3("Message:", err, "\n");
#else
jl_loader_print_stderr3("Message:", dlerror(), "\n");
char *dlerr = dlerror();
if (dlerr != NULL) {
jl_loader_print_stderr3("Message:", dlerr, "\n");
}
#endif
exit(1);
}
Expand Down Expand Up @@ -133,7 +136,10 @@ JL_DLLEXPORT const char * jl_get_libdir()
Dl_info info;
if (!dladdr(&jl_get_libdir, &info)) {
jl_loader_print_stderr("ERROR: Unable to dladdr(&jl_get_libdir)!\n");
jl_loader_print_stderr3("Message:", dlerror(), "\n");
char *dlerr = dlerror();
if (dlerr != NULL) {
jl_loader_print_stderr3("Message:", dlerr, "\n");
}
exit(1);
}
strcpy(lib_dir, info.dli_fname);
Expand Down

0 comments on commit 0a7d5d1

Please sign in to comment.