What version are you looking at? opj_image_create0() should be
handling the initialization, not the caller, which in my copy of
svn528 looks like this:
opj_image_t* opj_image_create0(void) {
opj_image_t *image = (opj_image_t*)opj_calloc(1, sizeof(opj_image_t));
return image;
}
The entire structure is initialized to zero by calloc(). Thus
image->comps should be NULL already when opj_image_create0() returns.
Incidentally, free()ing NULL is a valid no-op, so the null checks are
un-neccessary, opj_image_destroy() can be reduced to this:
void OPJ_CALLCONV opj_image_destroy(opj_image_t *image) {
int i;
if(image->comps) {
/* image components */
for(i = 0; i < image->numcomps; i++) {
opj_image_comp_t *image_comp = &image->comps[i];
opj_free(image_comp->data);
}
opj_free(image->comps);
}
opj_free(image);
}
> Note that I ran into this WITH a secondlife client, but do not run
> into it normally,
> only when today I switched to some different grid. The source speak
> for itself
> though: this is a bug.
Looks correct to me, as of svn528 at least. But I'm getting sleepy so
I might be missing something.
If you can provide a test case image, valgrind will reveal all. Also,
such a test case can go into a test suite to ensure it never breaks
again.