gpt4 book ai didi

c - 如何抑制来自 gpgme 的 valgrind 警告?

转载 作者:太空宇宙 更新时间:2023-11-04 04:18:54 26 4
gpt4 key购买 nike

我正在尝试在我的代码中使用 GPGME 来验证一些签名。然而,简单地初始化和释放 GPGME 上下文会导致 valgrind 发出大量警告。

例如:

#include <gpgme.h>

int main() {
gpgme_check_version(NULL);
gpgme_ctx_t my_ctx;
gpgme_error_t gpg_err;

gpg_err = gpgme_new(&my_ctx);

gpgme_release(my_ctx);

return 0;
}

gcc -lgpgme -lassuan -lgpg-error main.c 编译它,然后在 valgrind 下运行它。从 valgrind -v ./a.out 来看,这段代码似乎启动了 6 个不同的进程。我已经复制了相关的警告信息:

==19158== Warning: invalid file descriptor 1024 in syscall close()
==19158== at 0x558DBC4: close (in /usr/lib/libc-2.26.so)
==19158== by 0x4E65DF8: ??? (in /usr/lib/libgpgme.so.11.19.0)
==19158== by 0x4E66D65: ??? (in /usr/lib/libgpgme.so.11.19.0)
==19158== by 0x4E6736B: ??? (in /usr/lib/libgpgme.so.11.19.0)
==19158== by 0x4E56572: gpgme_get_engine_info (in /usr/lib/libgpgme.so.11.19.0)
==19158== by 0x4E56C87: ??? (in /usr/lib/libgpgme.so.11.19.0)
==19158== by 0x4E6838F: gpgme_new (in /usr/lib/libgpgme.so.11.19.0)
==19158== by 0x10880B: main (in /home/thedoctor/Programming/gpgmetest/mytest)
==19158== Warning: invalid file descriptor 1025 in syscall close()
==19158== at 0x558DBC4: close (in /usr/lib/libc-2.26.so)
==19158== by 0x4E65DF8: ??? (in /usr/lib/libgpgme.so.11.19.0)
==19158== by 0x4E66D65: ??? (in /usr/lib/libgpgme.so.11.19.0)
==19158== by 0x4E6736B: ??? (in /usr/lib/libgpgme.so.11.19.0)
==19158== by 0x4E56572: gpgme_get_engine_info (in /usr/lib/libgpgme.so.11.19.0)
==19158== by 0x4E56C87: ??? (in /usr/lib/libgpgme.so.11.19.0)
==19158== by 0x4E6838F: gpgme_new (in /usr/lib/libgpgme.so.11.19.0)
==19158== by 0x10880B: main (in /home/thedoctor/Programming/gpgmetest/mytest)
==19158== Warning: invalid file descriptor 1026 in syscall close()
==19158== at 0x558DBC4: close (in /usr/lib/libc-2.26.so)
==19158== by 0x4E65DF8: ??? (in /usr/lib/libgpgme.so.11.19.0)
==19158== by 0x4E66D65: ??? (in /usr/lib/libgpgme.so.11.19.0)
==19158== by 0x4E6736B: ??? (in /usr/lib/libgpgme.so.11.19.0)
==19158== by 0x4E56572: gpgme_get_engine_info (in /usr/lib/libgpgme.so.11.19.0)
==19158== by 0x4E56C87: ??? (in /usr/lib/libgpgme.so.11.19.0)
==19158== by 0x4E6838F: gpgme_new (in /usr/lib/libgpgme.so.11.19.0)
==19158== by 0x10880B: main (in /home/thedoctor/Programming/gpgmetest/mytest)
==19158== Warning: invalid file descriptor 1027 in syscall close()
==19158== Use --log-fd=<number> to select an alternative log fd.
==19158== at 0x558DBC4: close (in /usr/lib/libc-2.26.so)
==19158== by 0x4E65DF8: ??? (in /usr/lib/libgpgme.so.11.19.0)
==19158== by 0x4E66D65: ??? (in /usr/lib/libgpgme.so.11.19.0)
==19158== by 0x4E6736B: ??? (in /usr/lib/libgpgme.so.11.19.0)
==19158== by 0x4E56572: gpgme_get_engine_info (in /usr/lib/libgpgme.so.11.19.0)
==19158== by 0x4E56C87: ??? (in /usr/lib/libgpgme.so.11.19.0)
==19158== by 0x4E6838F: gpgme_new (in /usr/lib/libgpgme.so.11.19.0)
==19158== by 0x10880B: main (in /home/thedoctor/Programming/gpgmetest/mytest)
==19158== Warning: invalid file descriptor 1028 in syscall close()
==19158== at 0x558DBC4: close (in /usr/lib/libc-2.26.so)
==19158== by 0x4E65DF8: ??? (in /usr/lib/libgpgme.so.11.19.0)
==19158== by 0x4E66D65: ??? (in /usr/lib/libgpgme.so.11.19.0)
==19158== by 0x4E6736B: ??? (in /usr/lib/libgpgme.so.11.19.0)
==19158== by 0x4E56572: gpgme_get_engine_info (in /usr/lib/libgpgme.so.11.19.0)
==19158== by 0x4E56C87: ??? (in /usr/lib/libgpgme.so.11.19.0)
==19158== by 0x4E6838F: gpgme_new (in /usr/lib/libgpgme.so.11.19.0)
==19158== by 0x10880B: main (in /home/thedoctor/Programming/gpgmetest/mytest)
==19158== Warning: invalid file descriptor 1029 in syscall close()
==19158== at 0x558DBC4: close (in /usr/lib/libc-2.26.so)
==19158== by 0x4E65DF8: ??? (in /usr/lib/libgpgme.so.11.19.0)
==19158== by 0x4E66D65: ??? (in /usr/lib/libgpgme.so.11.19.0)
==19158== by 0x4E6736B: ??? (in /usr/lib/libgpgme.so.11.19.0)
==19158== by 0x4E56572: gpgme_get_engine_info (in /usr/lib/libgpgme.so.11.19.0)
==19158== by 0x4E56C87: ??? (in /usr/lib/libgpgme.so.11.19.0)
==19158== by 0x4E6838F: gpgme_new (in /usr/lib/libgpgme.so.11.19.0)
==19158== by 0x10880B: main (in /home/thedoctor/Programming/gpgmetest/mytest)

对总共 6 个不同的进程重复完全相同的一组警告。似乎 GPGME 试图关闭一些不属于自己的文件描述符。

我的问题有两个:

  1. 我使用的 gpgme API 有误吗?我还需要做些什么吗?
  2. 如果 API 的使用正确,我该如何抑制来自 valgrind 的这些警告?

我似乎无法让 valgrind 抑制这些警告。运行 valgrind --gen-suppressions=all -v ./a.out 不会在输出中显示任何抑制。我想那是因为这些是警告而不是真正的错误。我试着自己写一个抑制,但我不确定应该是什么类型。通常,当我不得不编写抑制时,它们是针对 Memcheck:Leak 的。但是这些警告属于哪一类呢?

编辑:这是我尝试写的抑制:

{
gpgme-leak-fd
fun:close
...
fun:gpgme_new
}

编辑 2:我试图悬赏,但它已过期。如果您对此有一个有效的答案,我会悬赏 100 个代表。

最佳答案

以下是 Dan McGee 编写的 GPGME 的一些规则,摘自 here :

{
gpgme-static-get-engine-info
Memcheck:Leak
fun:malloc
...
fun:gpgme_get_engine_info
}
{
gpgme-static-set-engine-info
Memcheck:Leak
fun:malloc
...
fun:_gpgme_set_engine_info
fun:gpgme_set_engine_info
}
{
gpgme-static-set-locale
Memcheck:Leak
fun:malloc
fun:strdup
fun:gpgme_set_locale
}

关于c - 如何抑制来自 gpgme 的 valgrind 警告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48712540/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com