mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-14 03:21:44 +03:00
Merge pull request #5111 from cgohlke/patch-3
Fix dereferencing of potential null pointers
This commit is contained in:
commit
cf530b8d9c
|
@ -29,11 +29,13 @@
|
||||||
void
|
void
|
||||||
ImagingHistogramDelete(ImagingHistogram h)
|
ImagingHistogramDelete(ImagingHistogram h)
|
||||||
{
|
{
|
||||||
|
if (h) {
|
||||||
if (h->histogram) {
|
if (h->histogram) {
|
||||||
free(h->histogram);
|
free(h->histogram);
|
||||||
}
|
}
|
||||||
free(h);
|
free(h);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ImagingHistogram
|
ImagingHistogram
|
||||||
ImagingHistogramNew(Imaging im)
|
ImagingHistogramNew(Imaging im)
|
||||||
|
@ -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) {
|
||||||
|
return (ImagingHistogram) ImagingError_MemoryError();
|
||||||
|
}
|
||||||
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) {
|
||||||
|
free(h);
|
||||||
|
return (ImagingHistogram) ImagingError_MemoryError();
|
||||||
|
}
|
||||||
|
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
@ -75,6 +84,9 @@ ImagingGetHistogram(Imaging im, Imaging imMask, void* minmax)
|
||||||
}
|
}
|
||||||
|
|
||||||
h = ImagingHistogramNew(im);
|
h = ImagingHistogramNew(im);
|
||||||
|
if (!h) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (imMask) {
|
if (imMask) {
|
||||||
/* mask */
|
/* mask */
|
||||||
|
|
Loading…
Reference in New Issue
Block a user