gpt4 book ai didi

c - pango+cairo Hello World 泄漏

转载 作者:太空宇宙 更新时间:2023-11-03 23:44:29 26 4
gpt4 key购买 nike

我在 pangocairo hello world 示例中遇到泄漏问题。

#include <cairo.h>
#include <pango/pangocairo.h>

int main(int argc, char *argv[])
{
// 0
cairo_surface_t* surface=cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 240, 80);
// 1
cairo_t* cr=cairo_create(surface);

// 2
PangoFontDescription* font_description=pango_font_description_new();
pango_font_description_set_family(font_description,"serif");
pango_font_description_set_weight(font_description,PANGO_WEIGHT_BOLD);
pango_font_description_set_absolute_size(font_description,32*PANGO_SCALE);

// 3
PangoLayout* layout=pango_cairo_create_layout(cr);

pango_layout_set_font_description(layout,font_description);
pango_layout_set_text(layout,"Hello, world",-1);
cairo_set_source_rgb (cr, 0.0, 0.0, 1.0);
cairo_move_to (cr, 10.0, 50.0);
pango_cairo_show_layout(cr,layout);

// 3
g_object_unref(layout);

// 2
pango_font_description_free(font_description);

// 1
cairo_destroy (cr);

cairo_surface_write_to_png (surface, "hello.png");

// 0
cairo_surface_destroy (surface);
return 0;
}

Valgrind 输出

==5178==    definitely lost: 7,936 bytes in 28 blocks
==5178== indirectly lost: 8,510 bytes in 374 blocks
==5178== possibly lost: 1,514 bytes in 21 blocks
==5178== still reachable: 567,835 bytes in 5,069 block

并提示 libfontconfig 和 glib。上面有没有遗漏的清理?如果不是我应该关心它(发布错误报告),还是 GNOME 项目的懒惰免费政策再次出现?

最佳答案

我可以从中得到这个

==8376==    definitely lost: 3,840 bytes in 12 blocks
==8376== indirectly lost: 7,822 bytes in 339 blocks
==8376== possibly lost: 1,514 bytes in 21 blocks
==8376== still reachable: 573,848 bytes in 4,977 blocks

==8394==    definitely lost: 0 bytes in 0 blocks
==8394== indirectly lost: 0 bytes in 0 blocks
==8394== possibly lost: 1,514 bytes in 21 blocks
==8394== still reachable: 60,064 bytes in 368 blocks

通过添加

    pango_cairo_font_map_set_default(NULL);
cairo_debug_reset_static_data();
FcFini();

在文件末尾。注意 FcFini()需要额外的 #include <fontconfig/fontconfig.h>并链接到 fontconfig。

快速浏览一下,来自 valgrind 的其余投诉来自 GLib 的类型系统设置。据我所知,要消除这些误报,我们无能为力。

关于c - pango+cairo Hello World 泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37251165/

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