Skip to content

Commit 25c24e4

Browse files
committed
Close file when error is returned
1 parent 562b9d2 commit 25c24e4

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

Modules/_testcapimodule.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2021,6 +2021,7 @@ call_pyobject_print(PyObject *self, PyObject * args)
20212021
}
20222022

20232023
if (PyObject_Print(object, fp, flags) < 0) {
2024+
fclose(fp);
20242025
return NULL;
20252026
}
20262027

@@ -2042,6 +2043,7 @@ pyobject_print_null(PyObject *self, PyObject *args)
20422043
fp = _Py_fopen_obj(filename, "w+");
20432044

20442045
if (PyObject_Print(NULL, fp, 0) < 0) {
2046+
fclose(fp);
20452047
return NULL;
20462048
}
20472049

@@ -2071,6 +2073,7 @@ pyobject_print_noref_object(PyObject *self, PyObject *args)
20712073
fp = _Py_fopen_obj(filename, "w+");
20722074

20732075
if (PyObject_Print(test_string, fp, 0) < 0){
2076+
fclose(fp);
20742077
return NULL;
20752078
}
20762079

@@ -2096,6 +2099,7 @@ pyobject_print_os_error(PyObject *self, PyObject *args)
20962099
fp = _Py_fopen_obj(filename, "r");
20972100

20982101
if (PyObject_Print(test_string, fp, 0) < 0) {
2102+
fclose(fp);
20992103
return NULL;
21002104
}
21012105

0 commit comments

Comments
 (0)