[Xcb] to free or not to free

Vincent Torri Vincent.Torri at iecn.u-nancy.fr
Tue Dec 6 01:22:27 PST 2005


hey,

I'm writing an xlib-like function for the render extension (i want to put
it in xcb_convenient) :

XCBRenderFindVisualFormat (XCBConnection *c, XCBVISUALID visual)
{
  XCBRenderQueryPictFormatsCookie cookie;
  XCBRenderQueryPictFormatsRep   *rep;
  XCBRenderPICTSCREENIter         screen_iter;
  XCBRenderPICTFORMINFOIter       forminfo_iter;
  XCBRenderPICTFORMAT             format = { 0 };

  cookie = XCBRenderQueryPictFormats (c);
  rep = XCBRenderQueryPictFormatsReply (c, cookie, NULL);
  if (!rep)
    return NULL;

  screen_iter = XCBRenderQueryPictFormatsScreensIter (rep);
  for (; screen_iter.rem; XCBRenderPICTSCREENNext (&screen_iter))
    {
      XCBRenderPICTDEPTHIter depth_iter;

      depth_iter = XCBRenderPICTSCREENDepthsIter (screen_iter.data);
      for (; depth_iter.rem; XCBRenderPICTDEPTHNext (&depth_iter))
        {
          XCBRenderPICTVISUALIter visual_iter;

          visual_iter = XCBRenderPICTDEPTHVisualsIter (depth_iter.data);
          for (; visual_iter.rem; XCBRenderPICTVISUALNext (&visual_iter))
            {
              if (visual == iter.data->visual)
                {
                  format = iter.data->format;
                }
            }
        }
    }

  if (format.xid != 0)
    {
      forminfo_iter = XCBRenderQueryPictFormatsFormatsIter (rep);
      for (; forminfo_iter.rem; XCBRenderPICTFORMINFONext
(&forminfo_iter))
        {
          if (forminfo_iter.data->id == format.id)
            {
              free (rep);

              return forminfo_iter.data;
            }
        }
    }
  free (rep);

  return NULL;
}

just before I return forminfo_iter.data, I free rep. Usually, the data is
in the chunk of memory of rep. So I guess that my code above is wrong. Am
I right ? Should I do a memcpy ?

Vincent


More information about the Xcb mailing list