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

Skip to content

Commit 150b7d7

Browse files
committed
Remove curses temp file consistently.
1 parent d2cf20e commit 150b7d7

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

Modules/_cursesmodule.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,11 +1299,13 @@ PyCursesWindow_PutWin(PyCursesWindowObject *self, PyObject *stream)
12991299
fp = fdopen(fd, "wb+");
13001300
if (fp == NULL) {
13011301
close(fd);
1302+
remove(fn);
13021303
return PyErr_SetFromErrnoWithFilename(PyExc_IOError, fn);
13031304
}
13041305
res = PyCursesCheckERR(putwin(self->win, fp), "putwin");
13051306
if (res == NULL) {
13061307
fclose(fp);
1308+
remove(fn);
13071309
return res;
13081310
}
13091311
fseek(fp, 0, 0);
@@ -1785,11 +1787,13 @@ PyCurses_GetWin(PyCursesWindowObject *self, PyObject *stream)
17851787
fp = fdopen(fd, "wb+");
17861788
if (fp == NULL) {
17871789
close(fd);
1790+
remove(fn);
17881791
return PyErr_SetFromErrnoWithFilename(PyExc_IOError, fn);
17891792
}
17901793
data = PyObject_CallMethod(stream, "read", "");
17911794
if (data == NULL) {
17921795
fclose(fp);
1796+
remove(fn);
17931797
return NULL;
17941798
}
17951799
if (!PyBytes_Check(data)) {
@@ -1798,13 +1802,15 @@ PyCurses_GetWin(PyCursesWindowObject *self, PyObject *stream)
17981802
data->ob_type->tp_name);
17991803
Py_DECREF(data);
18001804
fclose(fp);
1805+
remove(fn);
18011806
return NULL;
18021807
}
18031808
fwrite(PyBytes_AS_STRING(data), 1, PyBytes_GET_SIZE(data), fp);
18041809
Py_DECREF(data);
18051810
fseek(fp, 0, 0);
18061811
win = getwin(fp);
18071812
fclose(fp);
1813+
remove(fn);
18081814
if (win == NULL) {
18091815
PyErr_SetString(PyCursesError, catchall_NULL);
18101816
return NULL;

0 commit comments

Comments
 (0)