[Python-checkins] r52015 - in python/branches/release24-maint: Misc/NEWS Modules/_cursesmodule.c
andrew.kuchling
python-checkins at python.org
Wed Sep 27 21:02:03 CEST 2006
Author: andrew.kuchling
Date: Wed Sep 27 21:02:02 2006
New Revision: 52015
Modified:
python/branches/release24-maint/Misc/NEWS
python/branches/release24-maint/Modules/_cursesmodule.c
Log:
[Backport rev.51254 from neal.norwitz]
Handle failure from PyModule_GetDict() (Klocwork 208).
Fix a bunch of refleaks in the init of the module. This would only be found
when running python -v.
Modified: python/branches/release24-maint/Misc/NEWS
==============================================================================
--- python/branches/release24-maint/Misc/NEWS (original)
+++ python/branches/release24-maint/Misc/NEWS Wed Sep 27 21:02:02 2006
@@ -61,6 +61,9 @@
- Bug #1471938: Fix curses module build problem on Solaris 8; patch by
Paul Eggert.
+- cursesmodule: fix a number of reference leaks with 'python -v'; handle
+ failure from PyModule_GetDict (Klocwork 208).
+
- Bug #1512695: cPickle.loads could crash if it was interrupted with
a KeyboardInterrupt.
Modified: python/branches/release24-maint/Modules/_cursesmodule.c
==============================================================================
--- python/branches/release24-maint/Modules/_cursesmodule.c (original)
+++ python/branches/release24-maint/Modules/_cursesmodule.c Wed Sep 27 21:02:02 2006
@@ -1784,7 +1784,6 @@
PyCurses_InitScr(PyObject *self)
{
WINDOW *win;
- PyObject *nlines, *cols;
if (initialised == TRUE) {
wrefresh(stdscr);
@@ -1803,7 +1802,12 @@
/* This was moved from initcurses() because it core dumped on SGI,
where they're not defined until you've called initscr() */
#define SetDictInt(string,ch) \
- PyDict_SetItemString(ModDict,string,PyInt_FromLong((long) (ch)));
+ do { \
+ PyObject *o = PyInt_FromLong((long) (ch)); \
+ if (o && PyDict_SetItemString(ModDict, string, o) == 0) { \
+ Py_DECREF(o); \
+ } \
+ } while (0)
/* Here are some graphic symbols you can use */
SetDictInt("ACS_ULCORNER", (ACS_ULCORNER));
@@ -1872,12 +1876,8 @@
SetDictInt("ACS_STERLING", (ACS_STERLING));
#endif
- nlines = PyInt_FromLong((long) LINES);
- PyDict_SetItemString(ModDict, "LINES", nlines);
- Py_DECREF(nlines);
- cols = PyInt_FromLong((long) COLS);
- PyDict_SetItemString(ModDict, "COLS", cols);
- Py_DECREF(cols);
+ SetDictInt("LINES", LINES);
+ SetDictInt("COLS", COLS);
return (PyObject *)PyCursesWindow_New(win);
}
@@ -2487,6 +2487,8 @@
/* Add some symbolic constants to the module */
d = PyModule_GetDict(m);
+ if (d == NULL)
+ return;
ModDict = d; /* For PyCurses_InitScr to use later */
/* Add a CObject for the C API */
@@ -2600,6 +2602,10 @@
if (strncmp(key_n,"KEY_F(",6)==0) {
char *p1, *p2;
key_n2 = malloc(strlen(key_n)+1);
+ if (!key_n2) {
+ PyErr_NoMemory();
+ break;
+ }
p1 = key_n;
p2 = key_n2;
while (*p1) {
@@ -2612,7 +2618,7 @@
*p2 = (char)0;
} else
key_n2 = key_n;
- PyDict_SetItemString(d,key_n2,PyInt_FromLong((long) key));
+ SetDictInt(key_n2,key);
if (key_n2 != key_n)
free(key_n2);
}
More information about the Python-checkins
mailing list