8000 Fix cleanup of PNG structures on error. · matplotlib/matplotlib@23fa03e · GitHub
[go: up one dir, main page]

Skip to content

Commit 23fa03e

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

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
@@ -345,8 +345,12 @@ static PyObject *Py_write_png(PyObject *self, PyObject *args, PyObject *kwds)
345345
png_write_end(png_ptr, info_ptr);
346346

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

0 commit comments

Comments
 (0)
0