Fix dereferencing of potential null pointers

This commit is contained in:
Christoph Gohlke 2020-12-19 15:58:25 -08:00 committed by GitHub
parent c52c3ae3e2
commit fd4b0609ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -29,10 +29,12 @@
void void
ImagingHistogramDelete(ImagingHistogram h) ImagingHistogramDelete(ImagingHistogram h)
{ {
if (h->histogram) { if (h) {
free(h->histogram); if (h->histogram) {
free(h->histogram);
}
free(h);
} }
free(h);
} }
ImagingHistogram ImagingHistogram
@ -42,11 +44,18 @@ ImagingHistogramNew(Imaging im)
/* Create histogram descriptor */ /* Create histogram descriptor */
h = calloc(1, sizeof(struct ImagingHistogramInstance)); h = calloc(1, sizeof(struct ImagingHistogramInstance));
if (h == NULL) {
return NULL;
}
strncpy(h->mode, im->mode, IMAGING_MODE_LENGTH-1); strncpy(h->mode, im->mode, IMAGING_MODE_LENGTH-1);
h->mode[IMAGING_MODE_LENGTH-1] = 0; h->mode[IMAGING_MODE_LENGTH-1] = 0;
h->bands = im->bands; h->bands = im->bands;
h->histogram = calloc(im->pixelsize, 256 * sizeof(long)); h->histogram = calloc(im->pixelsize, 256 * sizeof(long));
if (h->histogram == NULL) {
free(h);
return NULL;
}
return h; return h;
} }
@ -75,6 +84,9 @@ ImagingGetHistogram(Imaging im, Imaging imMask, void* minmax)
} }
h = ImagingHistogramNew(im); h = ImagingHistogramNew(im);
if (h == NULL) {
return NULL;
}
if (imMask) { if (imMask) {
/* mask */ /* mask */