mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-02-04 21:50:54 +03:00
NULLing pointers on cleanup
This commit is contained in:
parent
3da6768a72
commit
7407371deb
|
@ -135,8 +135,8 @@ class ImageFile(Image.Image):
|
||||||
self.map = None
|
self.map = None
|
||||||
use_mmap = self.filename and len(self.tile) == 1
|
use_mmap = self.filename and len(self.tile) == 1
|
||||||
# As of pypy 2.1.0, memory mapping was failing here.
|
# As of pypy 2.1.0, memory mapping was failing here.
|
||||||
use_mmap = use_mmap and not hasattr(sys, 'pypy_version_info')
|
use_mmap = use_mmap and not hasattr(sys, 'pypy_version_info')
|
||||||
|
|
||||||
readonly = 0
|
readonly = 0
|
||||||
|
|
||||||
# look for read/seek overrides
|
# look for read/seek overrides
|
||||||
|
@ -473,7 +473,7 @@ def _save(im, fp, tile, bufsize=0):
|
||||||
break
|
break
|
||||||
if s < 0:
|
if s < 0:
|
||||||
raise IOError("encoder error %d when writing image file" % s)
|
raise IOError("encoder error %d when writing image file" % s)
|
||||||
#e.cleanup()
|
e.cleanup()
|
||||||
else:
|
else:
|
||||||
# slight speedup: compress to real file object
|
# slight speedup: compress to real file object
|
||||||
for e, b, o, a in tile:
|
for e, b, o, a in tile:
|
||||||
|
@ -484,7 +484,7 @@ def _save(im, fp, tile, bufsize=0):
|
||||||
s = e.encode_to_file(fh, bufsize)
|
s = e.encode_to_file(fh, bufsize)
|
||||||
if s < 0:
|
if s < 0:
|
||||||
raise IOError("encoder error %d when writing image file" % s)
|
raise IOError("encoder error %d when writing image file" % s)
|
||||||
#e.cleanup()
|
e.cleanup()
|
||||||
try:
|
try:
|
||||||
fp.flush()
|
fp.flush()
|
||||||
except: pass
|
except: pass
|
||||||
|
|
|
@ -68,7 +68,7 @@ j2k_skip(OPJ_OFF_T p_nb_bytes, void *p_user_data)
|
||||||
|
|
||||||
typedef void (*j2k_unpacker_t)(opj_image_t *in,
|
typedef void (*j2k_unpacker_t)(opj_image_t *in,
|
||||||
const JPEG2KTILEINFO *tileInfo,
|
const JPEG2KTILEINFO *tileInfo,
|
||||||
const UINT8 *data,
|
const UINT8 *data,
|
||||||
Imaging im);
|
Imaging im);
|
||||||
|
|
||||||
struct j2k_decode_unpacker {
|
struct j2k_decode_unpacker {
|
||||||
|
@ -335,7 +335,7 @@ j2ku_srgb_rgb(opj_image_t *in, const JPEG2KTILEINFO *tileinfo,
|
||||||
UINT8 *row = (UINT8 *)im->image[y0 + y] + x0 * 4;
|
UINT8 *row = (UINT8 *)im->image[y0 + y] + x0 * 4;
|
||||||
for (n = 0; n < 3; ++n)
|
for (n = 0; n < 3; ++n)
|
||||||
data[n] = &cdata[n][csiz[n] * y * w];
|
data[n] = &cdata[n][csiz[n] * y * w];
|
||||||
|
|
||||||
for (x = 0; x < w; ++x) {
|
for (x = 0; x < w; ++x) {
|
||||||
for (n = 0; n < 3; ++n) {
|
for (n = 0; n < 3; ++n) {
|
||||||
UINT32 word = 0;
|
UINT32 word = 0;
|
||||||
|
@ -388,7 +388,7 @@ j2ku_sycc_rgb(opj_image_t *in, const JPEG2KTILEINFO *tileinfo,
|
||||||
UINT8 *row_start = row;
|
UINT8 *row_start = row;
|
||||||
for (n = 0; n < 3; ++n)
|
for (n = 0; n < 3; ++n)
|
||||||
data[n] = &cdata[n][csiz[n] * y * w];
|
data[n] = &cdata[n][csiz[n] * y * w];
|
||||||
|
|
||||||
for (x = 0; x < w; ++x) {
|
for (x = 0; x < w; ++x) {
|
||||||
for (n = 0; n < 3; ++n) {
|
for (n = 0; n < 3; ++n) {
|
||||||
UINT32 word = 0;
|
UINT32 word = 0;
|
||||||
|
@ -442,7 +442,7 @@ j2ku_srgba_rgba(opj_image_t *in, const JPEG2KTILEINFO *tileinfo,
|
||||||
UINT8 *row = (UINT8 *)im->image[y0 + y] + x0 * 4;
|
UINT8 *row = (UINT8 *)im->image[y0 + y] + x0 * 4;
|
||||||
for (n = 0; n < 4; ++n)
|
for (n = 0; n < 4; ++n)
|
||||||
data[n] = &cdata[n][csiz[n] * y * w];
|
data[n] = &cdata[n][csiz[n] * y * w];
|
||||||
|
|
||||||
for (x = 0; x < w; ++x) {
|
for (x = 0; x < w; ++x) {
|
||||||
for (n = 0; n < 4; ++n) {
|
for (n = 0; n < 4; ++n) {
|
||||||
UINT32 word = 0;
|
UINT32 word = 0;
|
||||||
|
@ -494,7 +494,7 @@ j2ku_sycca_rgba(opj_image_t *in, const JPEG2KTILEINFO *tileinfo,
|
||||||
UINT8 *row_start = row;
|
UINT8 *row_start = row;
|
||||||
for (n = 0; n < 4; ++n)
|
for (n = 0; n < 4; ++n)
|
||||||
data[n] = &cdata[n][csiz[n] * y * w];
|
data[n] = &cdata[n][csiz[n] * y * w];
|
||||||
|
|
||||||
for (x = 0; x < w; ++x) {
|
for (x = 0; x < w; ++x) {
|
||||||
for (n = 0; n < 4; ++n) {
|
for (n = 0; n < 4; ++n) {
|
||||||
UINT32 word = 0;
|
UINT32 word = 0;
|
||||||
|
@ -587,13 +587,13 @@ j2k_decode_entry(Imaging im, ImagingCodecState state,
|
||||||
|
|
||||||
/* Setup decompression context */
|
/* Setup decompression context */
|
||||||
context->error_msg = NULL;
|
context->error_msg = NULL;
|
||||||
|
|
||||||
opj_set_default_decoder_parameters(¶ms);
|
opj_set_default_decoder_parameters(¶ms);
|
||||||
params.cp_reduce = context->reduce;
|
params.cp_reduce = context->reduce;
|
||||||
params.cp_layer = context->layers;
|
params.cp_layer = context->layers;
|
||||||
|
|
||||||
codec = opj_create_decompress(context->format);
|
codec = opj_create_decompress(context->format);
|
||||||
|
|
||||||
if (!codec) {
|
if (!codec) {
|
||||||
state->errcode = IMAGING_CODEC_BROKEN;
|
state->errcode = IMAGING_CODEC_BROKEN;
|
||||||
state->state = J2K_STATE_FAILED;
|
state->state = J2K_STATE_FAILED;
|
||||||
|
@ -616,7 +616,7 @@ j2k_decode_entry(Imaging im, ImagingCodecState state,
|
||||||
state->state = J2K_STATE_FAILED;
|
state->state = J2K_STATE_FAILED;
|
||||||
goto quick_exit;
|
goto quick_exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (n = 1; n < image->numcomps; ++n) {
|
for (n = 1; n < image->numcomps; ++n) {
|
||||||
if (image->comps[n].dx != 1 || image->comps[n].dy != 1) {
|
if (image->comps[n].dx != 1 || image->comps[n].dy != 1) {
|
||||||
state->errcode = IMAGING_CODEC_BROKEN;
|
state->errcode = IMAGING_CODEC_BROKEN;
|
||||||
|
@ -624,8 +624,8 @@ j2k_decode_entry(Imaging im, ImagingCodecState state,
|
||||||
goto quick_exit;
|
goto quick_exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Colorspace Number of components PIL mode
|
Colorspace Number of components PIL mode
|
||||||
------------------------------------------------------
|
------------------------------------------------------
|
||||||
sRGB 3 RGB
|
sRGB 3 RGB
|
||||||
|
@ -633,22 +633,22 @@ j2k_decode_entry(Imaging im, ImagingCodecState state,
|
||||||
gray 1 L or I
|
gray 1 L or I
|
||||||
gray 2 LA
|
gray 2 LA
|
||||||
YCC 3 YCbCr
|
YCC 3 YCbCr
|
||||||
|
|
||||||
|
|
||||||
If colorspace is unspecified, we assume:
|
If colorspace is unspecified, we assume:
|
||||||
|
|
||||||
Number of components Colorspace
|
Number of components Colorspace
|
||||||
-----------------------------------------
|
-----------------------------------------
|
||||||
1 gray
|
1 gray
|
||||||
2 gray (+ alpha)
|
2 gray (+ alpha)
|
||||||
3 sRGB
|
3 sRGB
|
||||||
4 sRGB (+ alpha)
|
4 sRGB (+ alpha)
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Find the correct unpacker */
|
/* Find the correct unpacker */
|
||||||
color_space = image->color_space;
|
color_space = image->color_space;
|
||||||
|
|
||||||
if (color_space == OPJ_CLRSPC_UNSPECIFIED) {
|
if (color_space == OPJ_CLRSPC_UNSPECIFIED) {
|
||||||
switch (image->numcomps) {
|
switch (image->numcomps) {
|
||||||
case 1: case 2: color_space = OPJ_CLRSPC_GRAY; break;
|
case 1: case 2: color_space = OPJ_CLRSPC_GRAY; break;
|
||||||
|
@ -668,7 +668,7 @@ j2k_decode_entry(Imaging im, ImagingCodecState state,
|
||||||
if (!unpack) {
|
if (!unpack) {
|
||||||
state->errcode = IMAGING_CODEC_BROKEN;
|
state->errcode = IMAGING_CODEC_BROKEN;
|
||||||
state->state = J2K_STATE_FAILED;
|
state->state = J2K_STATE_FAILED;
|
||||||
goto quick_exit;
|
goto quick_exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Decode the image tile-by-tile; this means we only need use as much
|
/* Decode the image tile-by-tile; this means we only need use as much
|
||||||
|
@ -797,6 +797,8 @@ ImagingJpeg2KDecodeCleanup(ImagingCodecState state) {
|
||||||
if (context->error_msg)
|
if (context->error_msg)
|
||||||
free ((void *)context->error_msg);
|
free ((void *)context->error_msg);
|
||||||
|
|
||||||
|
context->error_msg = NULL;
|
||||||
|
|
||||||
if (context->decoder)
|
if (context->decoder)
|
||||||
ImagingIncrementalCodecDestroy(context->decoder);
|
ImagingIncrementalCodecDestroy(context->decoder);
|
||||||
|
|
||||||
|
|
|
@ -303,7 +303,7 @@ j2k_encode_entry(Imaging im, ImagingCodecState state,
|
||||||
prec = 16;
|
prec = 16;
|
||||||
bpp = 12;
|
bpp = 12;
|
||||||
} else if (strcmp (im->mode, "LA") == 0) {
|
} else if (strcmp (im->mode, "LA") == 0) {
|
||||||
components = 2;
|
components = 2;
|
||||||
color_space = OPJ_CLRSPC_GRAY;
|
color_space = OPJ_CLRSPC_GRAY;
|
||||||
pack = j2k_pack_la;
|
pack = j2k_pack_la;
|
||||||
} else if (strcmp (im->mode, "RGB") == 0) {
|
} else if (strcmp (im->mode, "RGB") == 0) {
|
||||||
|
@ -340,7 +340,7 @@ j2k_encode_entry(Imaging im, ImagingCodecState state,
|
||||||
context->error_msg = NULL;
|
context->error_msg = NULL;
|
||||||
|
|
||||||
opj_set_default_encoder_parameters(¶ms);
|
opj_set_default_encoder_parameters(¶ms);
|
||||||
|
|
||||||
params.image_offset_x0 = context->offset_x;
|
params.image_offset_x0 = context->offset_x;
|
||||||
params.image_offset_y0 = context->offset_y;
|
params.image_offset_y0 = context->offset_y;
|
||||||
|
|
||||||
|
@ -546,8 +546,8 @@ ImagingJpeg2KEncode(Imaging im, ImagingCodecState state, UINT8 *buf, int bytes)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (state->state == J2K_STATE_START) {
|
if (state->state == J2K_STATE_START) {
|
||||||
int seekable = (context->format != OPJ_CODEC_J2K
|
int seekable = (context->format != OPJ_CODEC_J2K
|
||||||
? INCREMENTAL_CODEC_SEEKABLE
|
? INCREMENTAL_CODEC_SEEKABLE
|
||||||
: INCREMENTAL_CODEC_NOT_SEEKABLE);
|
: INCREMENTAL_CODEC_NOT_SEEKABLE);
|
||||||
|
|
||||||
context->encoder = ImagingIncrementalCodecCreate(j2k_encode_entry,
|
context->encoder = ImagingIncrementalCodecCreate(j2k_encode_entry,
|
||||||
|
@ -582,6 +582,8 @@ ImagingJpeg2KEncodeCleanup(ImagingCodecState state) {
|
||||||
if (context->error_msg)
|
if (context->error_msg)
|
||||||
free ((void *)context->error_msg);
|
free ((void *)context->error_msg);
|
||||||
|
|
||||||
|
context->error_msg = NULL;
|
||||||
|
|
||||||
if (context->encoder)
|
if (context->encoder)
|
||||||
ImagingIncrementalCodecDestroy(context->encoder);
|
ImagingIncrementalCodecDestroy(context->encoder);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user