Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6a735e2

Browse files
committed
Fix error reporting in png extension.
1 parent 927acf8 commit 6a735e2

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

src/_png.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,11 @@ Py::Object _png_module::write_png(const Py::Tuple& args)
262262
fclose(fp);
263263
}
264264

265-
return Py::Object();
265+
if (PyErr_Occurred()) {
266+
throw Py::Exception();
267+
} else {
268+
return Py::Object();
269+
}
266270
}
267271

268272
static void _read_png_data(PyObject* py_file_obj, png_bytep data, png_size_t length)
@@ -551,7 +555,12 @@ _png_module::_read_png(const Py::Object& py_fileobj, const bool float_result)
551555
}
552556
delete [] row_pointers;
553557

554-
return (PyObject*)A;
558+
if (PyErr_Occurred()) {
559+
Py_DECREF((PyObject *)A);
560+
return NULL;
561+
} else {
562+
return (PyObject *)A;
563+
}
555564
}
556565

557566
Py::Object

0 commit comments

Comments
 (0)