Skip to content

Commit 8e13db1

Browse files
committed
Fix cleanup of PNG structures on error.
If `info_ptr` isn't created, we should still destroy `png_ptr`.
1 parent ae00468 commit 8e13db1

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/_png.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,12 @@ static PyObject *Py_write_png(PyObject *self, PyObject *args, PyObject *kwds)
346346
png_write_end(png_ptr, info_ptr);
347347

348348
exit:
349-
if (png_ptr && info_ptr) {
350-
png_destroy_write_struct(&png_ptr, &info_ptr);
349+
if (png_ptr) {
350+
if (info_ptr) {
351+
png_destroy_write_struct(&png_ptr, &info_ptr);
352+
} else {
353+
png_destroy_write_struct(&png_ptr, NULL);
354+
}
351355
}
352356
if (PyErr_Occurred()) {
353357
Py_XDECREF(buff.str);

0 commit comments

Comments
 (0)