1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-01-20 14:03:39 +03:00

dlfcn: add new safe_dclose() helper

Let's allow destructing loaded module handles in our usual way that is
fine with NULL handles, and also returns the NULL handle again.
This commit is contained in:
Lennart Poettering 2023-01-25 11:54:44 +01:00
parent 6ec7a722ba
commit f2592ef0e1
2 changed files with 9 additions and 5 deletions

View File

@ -24,3 +24,11 @@ int dlopen_many_sym_or_warn_sentinel(void **dlp, const char *filename, int log_l
/* libbpf is a bit confused about type-safety and API compatibility. Provide a macro that can tape over that mess. Sad. */
#define DLSYM_ARG_FORCE(arg) \
&sym_##arg, STRINGIFY(arg)
static inline void *safe_dlclose(void *p) {
if (!p)
return NULL;
assert_se(dlclose(p) == 0);
return NULL;
}

View File

@ -111,11 +111,7 @@ void tpm2_context_destroy(struct tpm2_context *c) {
sym_Esys_Finalize(&c->esys_context);
c->tcti_context = mfree(c->tcti_context);
if (c->tcti_dl) {
dlclose(c->tcti_dl);
c->tcti_dl = NULL;
}
c->tcti_dl = safe_dlclose(c->tcti_dl);
}
static inline void Esys_Finalize_wrapper(ESYS_CONTEXT **c) {