Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/libImaging/Histo.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@
void
ImagingHistogramDelete(ImagingHistogram h)
{
if (h->histogram) {
free(h->histogram);
if (h) {
if (h->histogram) {
free(h->histogram);
}
free(h);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose this change is just to help in theory - but I'll still point out that in practice, with the other changes from this PR, ImagingHistogramDelete never receives a NULL argument.

}
free(h);
}

ImagingHistogram
Expand All @@ -42,11 +44,18 @@ ImagingHistogramNew(Imaging im)

/* Create histogram descriptor */
h = calloc(1, sizeof(struct ImagingHistogramInstance));
if (!h) {
return (ImagingHistogram) ImagingError_MemoryError();
}
strncpy(h->mode, im->mode, IMAGING_MODE_LENGTH-1);
h->mode[IMAGING_MODE_LENGTH-1] = 0;

h->bands = im->bands;
h->histogram = calloc(im->pixelsize, 256 * sizeof(long));
if (!h->histogram) {
free(h);
return (ImagingHistogram) ImagingError_MemoryError();
}

return h;
}
Expand Down Expand Up @@ -75,6 +84,9 @@ ImagingGetHistogram(Imaging im, Imaging imMask, void* minmax)
}

h = ImagingHistogramNew(im);
if (!h) {
return NULL;
}

if (imMask) {
/* mask */
Expand Down