调用 dlclose(NULL) 是否安全? [英] Is it safe to call dlclose(NULL)?

查看:105
本文介绍了调用 dlclose(NULL) 是否安全?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我将 null 指针传递给 dlclose 时,我会遇到崩溃.

I experience a crash when I pass a null pointer to dlclose.

在调用 dlclose 之前是否应该检查null?

Should I check for null before calling dlclose?

POSIX对此一无所知: http://pubs.opengroup.org/onlinepubs/7908799/xsh/dlclose.html

POSIX tells nothing about this: http://pubs.opengroup.org/onlinepubs/7908799/xsh/dlclose.html

是未定义的行为还是 dlclose 实现中的错误?

Is it undefined behaviour or a bug in dlclose implementation?

推荐答案

这很棘手.POSIX指出

This is tricky. POSIX states that

如果 handle 未引用打开的对象,则 dlclose()返回非零值

if handle does not refer to an open object, dlclose() returns a non-zero value

,从中可以推断出它应该为任意指针检测该指针是否指向打开的对象.Linux/Glibc版本显然没有进行这种检查,因此您需要自己检查 NULL .

from which you could infer that it should detect, for an arbitrary pointer, whether that pointer refers to an open object. The Linux/Glibc version apparently does no such check, so you'll want to check for NULL yourself.

[此外,Linux联机帮助页也不是很有帮助.关于 libdl 函数的行为是非常隐含的,在没有非常清楚地声明符合性的情况下遵从POSIX.]

[Aside, the Linux manpage isn't very helpful either. It's quite implicit about libdl functions' behavior, deferring to POSIX without very clearly claiming conformance.]

这篇关于调用 dlclose(NULL) 是否安全?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆