[Xcb] about xcb_image

Vincent Torri vtorri at univ-evry.fr
Sun Mar 9 13:14:18 PDT 2008

On Sun, 9 Mar 2008, Barton C Massey wrote:

> In message <Pine.LNX.4.64.0803091156000.5181 at grozny.maths.univ-evry.fr> you wrote:
>> I think that I know how to deal correctly with the new xcb_image, but I
>> think that i found a problem with xcb_image_create().
>> When base = data = NULL and size = ~0 (that is, when it's the user who
>> manages his data), image->base may be not NULL, because we didn't calloc
>> the xcb_image_t object. Hence, in xcb_image_destroy(), we try to free a
>> memory that has maybe not been allocated.
>> I have solved the problem by just setting image->base to NULL after line
>> 267. I think that it's faster than a calloc.
>> Is it a correct fix ?
> The comment right above 267 that says "when base = 0 && data
> == 0 && bytes == ~0 we just return the image structure and
> let the caller deal with getting the allocation right" was
> deliberate---my intent was that any caller that uses
> xcb_image_create() this way is responsible for initializing
> both base and data appropriately for what they're trying to
> do.  A typical usage of this mode is that you want to do
> something clever with the allocation, but you want
> xcb_image_create() to compute the image size for you first.

that's not very convenient. In that case (base = data = NULL, bytes = ~0), 
the user indeed manages memory himself. So data is set by the user and 
he should free it himself. There is no need of base in that case. So it's 
very error-prone to not set the base to NULL in xcb_image_create. Also, 
the documentation of xcb_image_create does not mention that we have to set 
the base to NULL. The doc of xcb_image_destroy mentions that it is freed, 
though (and the doc of that member too), but maybe it would be better to 
mention that in the doc of xcb_create.

Thank you for committing :-)


More information about the Xcb mailing list