GNOME Bugzilla – Bug 578493
vte.Terminal.set_background_image memory leak
Last modified: 2014-03-27 18:49:20 UTC
Please describe the problem: vte.Terminal.set_background_image does not release pixbuf objects. So python's gc can't free the objects and memory usage keep growing. Steps to reproduce: 1. Create vte.Terminal instance 2. Call set_background_image repeatedly 3. Actual results: Memory usage keep growing Expected results: Memory usage not grow Does this happen every time? yes Other information:
Created attachment 132409 [details] [review] Fix memleak This patch fix the problem. But I'm not a C programmer and I don't know what I do.
I don't think this patch is correct. In the saturation != 1.0 case, we create a new ref, so for symmetry alone we have to ref source_pixbuf here. The code below that unrefs the pixbuf again. Can you please attach a testcase to reproduce the leak? Or a valgrind log at least?
Created attachment 132459 [details] vte-memleak.py This python script reproduce the problem.
Only leak in the testcase that's background related: ==9626== 108 (16 direct, 92 indirect) bytes in 1 blocks are definitely lost in loss record 74 of 202 ==9626== at 0x4024D2E: malloc (vg_replace_malloc.c:207) ==9626== by 0x4024EAF: realloc (vg_replace_malloc.c:429) ==9626== by 0x46A564D: g_realloc (gmem.c:170) ==9626== by 0x461CE8F: g_object_weak_ref (gobject.c:1983) ==9626== by 0x461D159: g_object_add_weak_pointer (gobject.c:2050) ==9626== by 0x598F480: vte_bg_cache_add (vtebg.c:443) ==9626== by 0x598FD38: vte_bg_get_pixmap (vtebg.c:669) ==9626== by 0x59925C0: _vte_pangocairo_set_background_image (vtepangocairo.c:872) ==9626== by 0x5990AC9: _vte_draw_set_background_image (vtedraw.c:240) ==9626== by 0x598698A: vte_terminal_background_update (vte.c:12472) ==9626== by 0x598A193: update_repeat_timeout (vte.c:14073) ==9626== by 0x469FECD: g_timeout_dispatch (gmain.c:3253) ==9626== by 0x469C9D5: g_main_dispatch (gmain.c:1814) ==9626== by 0x469DEAD: g_main_context_dispatch (gmain.c:2367) ==9626== by 0x469E401: g_main_context_iterate (gmain.c:2448) ==9626== by 0x469EBE8: g_main_loop_run (gmain.c:2656) ==9626== by 0x4B3D84F: gtk_main (gtkmain.c:1204)
Created attachment 167594 [details] [review] Do not ref the pixbuf in the cache The leak is somewhere else; the cache item refs the pixbuf too which is wrong (weak ref will never work).
Created attachment 167597 [details] [review] Do not ref in cache and free on finalize Same as previous patch, but also unref the bg in finalize.
ChPe, can you review this please?
Err in finalize it should be terminal->pvt instead of pvt, sorry.
(In future, please use git format-patch, or git bz, when attaching patches.)
Created attachment 170111 [details] [review] fix a memory leak in cache This bug seems still not fixed in HEAD. I partly fixed it as in my attachment. This is basically the same as what Nick did in his patch in #6. The difference i think is, i added unref(), but he removed the ref(). Also I didn't noticed nor fixed a memory leak in finalize, so I think his patch is more complete.
Tried the patch from Eiichi and it works fine here, all the pixbuf are freed in Xfce terminal with this patch. Can this be applied please?
This tiny patch is still not applied and vte is still leaking pixbufs...
This is fixed on the vte-next branch and thus will be fixed on master once that branch lands.