Let's allow destructing loaded module handles in our usual way that is
fine with NULL handles, and also returns the NULL handle again.
/* 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;
+}
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) {