GSTREAMER最小程序泄漏内存
我有一个最小的 gstreamer program:
#include <gst/gst.h>
int main() {
gst_init(NULL, NULL);
gst_deinit();
}
我使用gcc test.c $(pkg-config(pkg-config) -fflags -libs gstreamer-1.0)-fsanitize = address
(GCC是版本12.1.0),运行它并从地址消毒剂中获取以下输出:
==87326==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 16384 byte(s) in 1 object(s) allocated from:
#0 0x7f53e28bfa89 in __interceptor_malloc /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:69
#1 0x7f53e26c1b19 in g_malloc (/usr/lib/libglib-2.0.so.0+0x5db19)
SUMMARY: AddressSanitizer: 16384 byte(s) leaked in 1 allocation(s).
我是GSTREAMER和GLIB的新手。这对于GSTREAMER程序来说是正常的吗?如果是这样,在使用消毒剂进行单元测试时,忽略此泄漏的一种优雅方式是什么?
I have a minimal GStreamer program:
#include <gst/gst.h>
int main() {
gst_init(NULL, NULL);
gst_deinit();
}
I build it with gcc test.c $(pkg-config --cflags --libs gstreamer-1.0) -fsanitize=address
(gcc is version 12.1.0), run it and get the following output from the address sanitizer:
==87326==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 16384 byte(s) in 1 object(s) allocated from:
#0 0x7f53e28bfa89 in __interceptor_malloc /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:69
#1 0x7f53e26c1b19 in g_malloc (/usr/lib/libglib-2.0.so.0+0x5db19)
SUMMARY: AddressSanitizer: 16384 byte(s) leaked in 1 allocation(s).
I'm new to GStreamer and GLib. Is this normal for GStreamer programs? And if it is, what would be an elegant way to ignore this leak when running unit tests with sanitizers?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题在于,有一些版本的 g_intern_string ,例如 libglib-2.0.so.0.6400.6 中的一个版本,当它们成长时,它们具有一个错误哈希地图的存储库数组,它们无法释放旧数组。
泄漏是在G_Intern_string的此拆卸中显示的最后一个指令:
碰巧的是,LibgStreamer使用该功能足以使水桶阵列需要增长,从而触发泄漏。
例如,在Github上,浅virib源表明该代码已更改。实际避免泄漏的最佳方法是尝试使用较新版本的libglib。
测试中泄漏的特定值实际上是初始存储桶阵列,该数组是在初始化libglib时分配的:
因此,要抑制消毒剂中的此类错误,而不是避免泄漏,您必须告诉它要忽略它用G_Malloc作为堆栈的一部分的任何分配(可能会使您丢失更明显的泄漏)或告诉它至少在初始化GLIB和可能涉及 g_intern_string+140 的任何堆栈,具体取决于您的程序是否最终导致G_INTERN_STRING被称为足够多次,以使水桶阵列生长不止一次。
The issue is that there are some versions of g_intern_string, for example, the one in libglib-2.0.so.0.6400.6, that have a bug where, when they grow the buckets array for a hash map, they fail to free the old array.
The leak is on the last instruction shown in this disassembly of g_intern_string:
It just happens that libgstreamer uses that function enough that the buckets array requires growth, triggering the leak.
A shallow look at the glib source, for example on github, suggests that this code has changed. The best way to actually avoid the leak would be to try to use a newer version of libglib.
The specific value that is leaked in your test is actually the initial buckets array, which is allocated when libglib is initialized:
So to suppress such errors in a sanitizer, as opposed to avoiding the leak, you'd either have to tell it to ignore any allocations with g_malloc as part of the stack (which may leave you subject to missing some more significant leaks) or to tell it to ignore at least that specific allocation made when glib is initialized and possibly any stacks involving g_intern_string+140, depending on whether your program eventually causes g_intern_string to be called sufficiently many times that the buckets array grows more than once.