summaryrefslogtreecommitdiffstats
path: root/Objects/structseq.c
diff options
context:
space:
mode:
authorNeal Norwitz <nnorwitz@gmail.com>2008-08-24 05:04:52 (GMT)
committerNeal Norwitz <nnorwitz@gmail.com>2008-08-24 05:04:52 (GMT)
commit18aa388ca084e1d40aa48c8c8f1b4f730c6fe059 (patch)
tree5701b8dbd43b407aa8dfa621e518bb7df75f6a6b /Objects/structseq.c
parent21d2ab7fe8a96244ea6cd2838e64ca8439089895 (diff)
downloadcpython-18aa388ca084e1d40aa48c8c8f1b4f730c6fe059.zip
cpython-18aa388ca084e1d40aa48c8c8f1b4f730c6fe059.tar.gz
cpython-18aa388ca084e1d40aa48c8c8f1b4f730c6fe059.tar.bz2
Fix:
* crashes on memory allocation failure found with failmalloc * memory leaks found with valgrind * compiler warnings in opt mode which would lead to invalid memory reads * problem using wrong name in decimal module reported by pychecker Update the valgrind suppressions file with new leaks that are small/one-time leaks we don't care about (ie, they are too hard to fix). TBR=barry TESTED=./python -E -tt ./Lib/test/regrtest.py -uall (both debug and opt modes) in opt mode: valgrind -q --leak-check=yes --suppressions=Misc/valgrind-python.supp \ ./python -E -tt ./Lib/test/regrtest.py -uall,-bsddb,-compiler \ -x test_logging test_ssl test_multiprocessing valgrind -q --leak-check=yes --suppressions=Misc/valgrind-python.supp \ ./python -E -tt ./Lib/test/regrtest.py test_multiprocessing for i in `seq 1 4000` ; do LD_PRELOAD=~/local/lib/libfailmalloc.so FAILMALLOC_INTERVAL=$i \ ./python -c pass done At least some of these fixes should probably be backported to 2.5.
Diffstat (limited to 'Objects/structseq.c')
-rw-r--r--Objects/structseq.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/Objects/structseq.c b/Objects/structseq.c
index b6126ba..ad246a1 100644
--- a/Objects/structseq.c
+++ b/Objects/structseq.c
@@ -32,6 +32,8 @@ PyStructSequence_New(PyTypeObject *type)
PyStructSequence *obj;
obj = PyObject_New(PyStructSequence, type);
+ if (obj == NULL)
+ return NULL;
Py_SIZE(obj) = VISIBLE_SIZE_TP(type);
return (PyObject*) obj;
@@ -522,10 +524,16 @@ PyStructSequence_InitType(PyTypeObject *type, PyStructSequence_Desc *desc)
Py_INCREF(type);
dict = type->tp_dict;
- PyDict_SetItemString(dict, visible_length_key,
- PyInt_FromLong((long) desc->n_in_sequence));
- PyDict_SetItemString(dict, real_length_key,
- PyInt_FromLong((long) n_members));
- PyDict_SetItemString(dict, unnamed_fields_key,
- PyInt_FromLong((long) n_unnamed_members));
+#define SET_DICT_FROM_INT(key, value) \
+ do { \
+ PyObject *v = PyInt_FromLong((long) value); \
+ if (v != NULL) { \
+ PyDict_SetItemString(dict, key, v); \
+ Py_DECREF(v); \
+ } \
+ } while (0)
+
+ SET_DICT_FROM_INT(visible_length_key, desc->n_in_sequence);
+ SET_DICT_FROM_INT(real_length_key, n_members);
+ SET_DICT_FROM_INT(unnamed_fields_key, n_unnamed_members);
}