0

I try to use cairo to draw_text on screen but mac Os X instrument tells me that I have dangling pointer cause by pango_layout_get_pixel_size or pango_layout_get_baseline .. actuelly the first function which needs to have PangoLines and store them in Layout variable. In every code show on the documentation and example you juste have to g_object_unref(layout) at the end ... but still ... those pointers allocate by itemized_state_init (inside pango_layout_get_pixel_size for ex) are not freed.

Am I doing something wrong ?

double posX = somevalue;
double posY = somevalue;
cairo_save (CurCairoState);
PangoLayout *layout = pango_cairo_create_layout (CurCairoState);
pango_layout_set_text (layout, text, -1);
pango_layout_set_font_description (layout, curCairoContext->font);
int width, height;

pango_layout_get_pixel_size (layout, &width, &height);

int b = (int)(pango_layout_get_baseline (layout) / PANGO_SCALE);

/* applying alignment attribute */
switch (curCairoContext->textAnchor) {
case GMiddle:
   posX = posX - (width / 2.0);
   break;
case GEnd:
   posX = posX - width;
   break;
}

cairo_move_to (CurCairoState, posX, posY - b);
pango_cairo_show_layout (CurCairoState, layout);

g_object_unref (layout);
cairo_restore (CurCairoState);

and the result of the allocation in Instrument

enter image description here

thanx to any reply !

EDIT: here is the new screenshot after using G_SLICE=always-malloc G_DEBUG=gc-friendly. Thoses dangling pointers became leaks for "instrument"

enter image description here

EDIT (no solution found) :

I downloaded the sources of pango-1.40.3, compiled it and installed it with markers of my own and I don't understand why I'have got those dangling pointers on MacOS because I'm going through : pango_layout_finalize and pango_layout_clear_lines and layout->ref_count=0 when I call g_obejct_unref (layout)

user1947994
  • 61
  • 1
  • 6
  • Run your code 1000 times in a loop. Is the leak 1000 timers larger? If not, then it's likely just some internal optimisation via some buffer. – Uli Schlachter Oct 03 '16 at 18:52
  • Also are you running with environment variables G_SLICE=always-malloc and G_DEBUG=gc-friendly as per e.g. https://testbit.eu/25012006-allocation-debugging-with-glib/ ? – Uli Schlachter Oct 03 '16 at 18:57
  • I tried the x1000 the code and the allocation grows up by 1000. So I do not think that they are optimisation buffers. Then I tried running the code under the environment variables G_SLICE=always-malloc and G_DEBUG=gc-friendly and then the dangling pointers became leaks for "instruments" and those leaks are pointing on the same functions such as pango_layout_get_pixel_size I will edit my question with a new screen shot with the use of the variables. tx – user1947994 Oct 04 '16 at 09:19

0 Answers0