Merge pull request #5111 from cgohlke/patch-3

Fix dereferencing of potential null pointers
This commit is contained in:
Andrew Murray 2020-12-27 12:21:09 +11:00 committed by GitHub
commit cf530b8d9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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
@ -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;
}
@ -75,6 +84,9 @@ ImagingGetHistogram(Imaging im, Imaging imMask, void* minmax)
}
h = ImagingHistogramNew(im);
if (!h) {
return NULL;
}
if (imMask) {
/* mask */