Skip to content

Commit

Permalink
Merge pull request #5111 from cgohlke/patch-3
Browse files Browse the repository at this point in the history
Fix dereferencing of potential null pointers
  • Loading branch information
radarhere committed Dec 27, 2020
2 parents 4e60680 + 51b8137 commit cf530b8
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/libImaging/Histo.c
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);
}
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

0 comments on commit cf530b8

Please sign in to comment.