[Xcb] about xcb_image

Barton C Massey bart at cs.pdx.edu
Sun Mar 9 11:35:50 PDT 2008

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 said, zeroing base and data on the return is harmless
and apparently might make a user error easier to find, so I
committed a patch that does this.


More information about the Xcb mailing list