Skip to content

Commit e68a1e2

Browse files
akxradarhere
andcommitted
geometry: clean up imOut if operation fails
Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com>
1 parent 8f86212 commit e68a1e2

1 file changed

Lines changed: 34 additions & 24 deletions

File tree

src/_imaging.c

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2189,30 +2189,40 @@ _transpose(ImagingObject *self, PyObject *args) {
21892189
return NULL;
21902190
}
21912191

2192-
if (imOut) {
2193-
switch (op) {
2194-
case 0:
2195-
(void)ImagingFlipLeftRight(imOut, imIn);
2196-
break;
2197-
case 1:
2198-
(void)ImagingFlipTopBottom(imOut, imIn);
2199-
break;
2200-
case 2:
2201-
(void)ImagingRotate90(imOut, imIn);
2202-
break;
2203-
case 3:
2204-
(void)ImagingRotate180(imOut, imIn);
2205-
break;
2206-
case 4:
2207-
(void)ImagingRotate270(imOut, imIn);
2208-
break;
2209-
case 5:
2210-
(void)ImagingTranspose(imOut, imIn);
2211-
break;
2212-
case 6:
2213-
(void)ImagingTransverse(imOut, imIn);
2214-
break;
2215-
}
2192+
if (!imOut) {
2193+
return NULL;
2194+
}
2195+
2196+
Imaging imTemp = NULL; // will be either NULL or imOut after the operation finishes
2197+
switch (op) {
2198+
case 0:
2199+
imTemp = ImagingFlipLeftRight(imOut, imIn);
2200+
break;
2201+
case 1:
2202+
imTemp = ImagingFlipTopBottom(imOut, imIn);
2203+
break;
2204+
case 2:
2205+
imTemp = ImagingRotate90(imOut, imIn);
2206+
break;
2207+
case 3:
2208+
imTemp = ImagingRotate180(imOut, imIn);
2209+
break;
2210+
case 4:
2211+
imTemp = ImagingRotate270(imOut, imIn);
2212+
break;
2213+
case 5:
2214+
imTemp = ImagingTranspose(imOut, imIn);
2215+
break;
2216+
case 6:
2217+
imTemp = ImagingTransverse(imOut, imIn);
2218+
break;
2219+
default:
2220+
PyErr_SetString(PyExc_ValueError, "No such transpose operation");
2221+
return NULL;
2222+
}
2223+
if (!imTemp) { // operation failed and will have set an exception
2224+
ImagingDelete(imOut);
2225+
return NULL;
22162226
}
22172227

22182228
return PyImagingNew(imOut);

0 commit comments

Comments
 (0)