gpt4 book ai didi

c - libwnck 中的内存泄漏

转载 作者:行者123 更新时间:2023-12-04 00:08:04 32 4
gpt4 key购买 nike

我尝试编译 libwnck's introduction 的第一个示例:

#include <libwnck/libwnck.h>
int main (int argc, char **argv)
{
WnckScreen *screen;
WnckWindow *active_window;
GList *window_l;

gdk_init (&argc, &argv);
screen = wnck_screen_get_default ();
wnck_screen_force_update (screen);
active_window = wnck_screen_get_active_window (screen);
for (window_l = wnck_screen_get_windows (screen); window_l != NULL; window_l = window_l->next)
{
WnckWindow *window = WNCK_WINDOW (window_l->data);
g_print ("%s%s\n", wnck_window_get_name (window),
window == active_window ? " (active)" : "");
}
wnck_shutdown();
}

使用此命令行:

gcc -o testwnck testwnck.cpp -DWNCK_I_KNOW_THIS_IS_UNSTABLE `pkg-config --libs libwnck-3.0` `pkg-config --cflags libwnck-3.0`

但是当我通过 valgrind 运行它时,出现了很多错误。例如:

==20365== 96 bytes in 2 blocks are possibly lost in loss record 876 of 1,019
==20365== at 0x4C28F40: malloc (vg_replace_malloc.c:296)
==20365== by 0x6F6E0A0: g_malloc (in /usr/lib64/libglib-2.0.so.0.4200.0)
==20365== by 0x6F84BB5: g_memdup (in /usr/lib64/libglib-2.0.so.0.4200.0)
==20365== by 0x6CFD364: type_iface_vtable_base_init_Wm (in /usr/lib64/libgobject-2.0.so.0.4200.0)
==20365== by 0x6CFE5BC: g_type_class_ref (in /usr/lib64/libgobject-2.0.so.0.4200.0)
==20365== by 0x6CE79D4: g_object_new_valist (in /usr/lib64/libgobject-2.0.so.0.4200.0)
==20365== by 0x6CE7BD3: g_object_new (in /usr/lib64/libgobject-2.0.so.0.4200.0)
==20365== by 0x6745E6B: gdk_pixbuf_new_from_data (in /usr/lib64/libgdk_pixbuf-2.0.so.0.3000.8)
==20365== by 0x4E60681: scaled_from_pixdata (in /usr/lib64/libwnck-3.so.0.2.2)
==20365== by 0x4E62DE7: _wnck_read_icons (in /usr/lib64/libwnck-3.so.0.2.2)
==20365== by 0x4E57F74: get_icons (in /usr/lib64/libwnck-3.so.0.2.2)
==20365== by 0x4E58DC6: force_update_now (in /usr/lib64/libwnck-3.so.0.2.2)

在从主函数返回之前添加对 wnck_shutdown() 的调用没有帮助。我该怎么做才能抑制这些错误?

编辑:我也尝试过使用来自 valgrind 的 gtk 抑制文件,但我仍然有错误。

最佳答案

如果在使用latest GLib suppression file时仍然报漏电, 那么请 file a bug against libwnck因为它很可能是 libwnck 本身的漏洞。

但是,我怀疑您看到的分配是 GObject 对每个新类实例执行一次的类型类分配之一,故意从不释放(它们本质上构成了运行时的一部分)。但这很好,因为它们只会在第一次使用类型时执行一次。抑制文件应该抑制它们。

关于c - libwnck 中的内存泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26834145/

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