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

Skip to content

Commit 2f99b24

Browse files
committed
Merged revisions 66006 via svnmerge from
svn+ssh://[email protected]/python/trunk TESTED=./python -E -tt ./Lib/test/regrtest.py -uall (both debug and opt modes) ........ r66006 | neal.norwitz | 2008-08-23 22:04:52 -0700 (Sat, 23 Aug 2008) | 25 lines 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. ........
1 parent c4b1535 commit 2f99b24

9 files changed

Lines changed: 73 additions & 12 deletions

File tree

Lib/decimal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5147,7 +5147,7 @@ def _dlog10(c, e, p):
51475147
log_tenpower = f*M # exact
51485148
else:
51495149
log_d = 0 # error < 2.31
5150-
log_tenpower = div_nearest(f, 10**-p) # error < 0.5
5150+
log_tenpower = _div_nearest(f, 10**-p) # error < 0.5
51515151

51525152
return _div_nearest(log_tenpower+log_d, 100)
51535153

Misc/NEWS

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ What's New in Python 3.0 release candidate 1
1212
Core and Builtins
1313
-----------------
1414

15+
- Fix crashes on memory allocation failure found with failmalloc.
16+
17+
- Fix memory leaks found with valgrind and update suppressions file.
18+
19+
- Fix compiler warnings in opt mode which would lead to invalid memory reads.
20+
21+
- Fix problem using wrong name in decimal module reported by pychecker.
22+
1523
- Issue #3650: Fixed a reference leak in bytes.split('x').
1624

1725
Library

Misc/valgrind-python.supp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,39 @@
4646
# Will need to fix that.
4747
#
4848

49+
{
50+
Suppress leaking the GIL. Happens once per process, see comment in ceval.c.
51+
Memcheck:Leak
52+
fun:malloc
53+
fun:PyThread_allocate_lock
54+
fun:PyEval_InitThreads
55+
}
56+
57+
{
58+
Suppress leaking the GIL after a fork.
59+
Memcheck:Leak
60+
fun:malloc
61+
fun:PyThread_allocate_lock
62+
fun:PyEval_ReInitThreads
63+
}
64+
65+
{
66+
Suppress leaking the autoTLSkey. This looks like it shouldn't leak though.
67+
Memcheck:Leak
68+
fun:malloc
69+
fun:PyThread_create_key
70+
fun:_PyGILState_Init
71+
fun:Py_InitializeEx
72+
fun:Py_Main
73+
}
74+
75+
{
76+
Hmmm, is this a real leak or like the GIL?
77+
Memcheck:Leak
78+
fun:malloc
79+
fun:PyThread_ReInitTLS
80+
}
81+
4982
{
5083
Handle PyMalloc confusing valgrind (possibly leaked)
5184
Memcheck:Leak

Modules/_ctypes/stgdict.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ StructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct)
408408
ffi_ofs = 0;
409409
}
410410

411+
assert(stgdict->format == NULL);
411412
if (isStruct && !isPacked) {
412413
stgdict->format = alloc_format_string(NULL, "T{");
413414
} else {
@@ -527,7 +528,9 @@ StructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct)
527528
#undef realdict
528529

529530
if (isStruct && !isPacked) {
531+
char *ptr = stgdict->format;
530532
stgdict->format = alloc_format_string(stgdict->format, "}");
533+
PyMem_Free(ptr);
531534
if (stgdict->format == NULL)
532535
return -1;
533536
}

Modules/_fileio.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
278278
ret = -1;
279279

280280
done:
281+
PyMem_Free(name);
281282
return ret;
282283
}
283284

Modules/signalmodule.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,8 @@ PyInit_signal(void)
796796
#if defined (HAVE_SETITIMER) || defined (HAVE_GETITIMER)
797797
ItimerError = PyErr_NewException("signal.ItimerError",
798798
PyExc_IOError, NULL);
799-
PyDict_SetItemString(d, "ItimerError", ItimerError);
799+
if (ItimerError != NULL)
800+
PyDict_SetItemString(d, "ItimerError", ItimerError);
800801
#endif
801802

802803
if (PyErr_Occurred()) {

Objects/stringlib/formatter.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,10 @@ format_int_or_long_internal(PyObject *value, const InternalFormatSpec *format,
641641
/* We know this can't fail, since we've already
642642
reserved enough space. */
643643
STRINGLIB_CHAR *pstart = p + n_leading_chars;
644-
int r = STRINGLIB_GROUPING(pstart, n_digits, n_digits,
644+
#ifndef NDEBUG
645+
int r =
646+
#endif
647+
STRINGLIB_GROUPING(pstart, n_digits, n_digits,
645648
spec.n_total+n_grouping_chars-n_leading_chars,
646649
NULL, 0);
647650
assert(r);

Objects/structseq.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ PyStructSequence_New(PyTypeObject *type)
3232
PyStructSequence *obj;
3333

3434
obj = PyObject_New(PyStructSequence, type);
35+
if (obj == NULL)
36+
return NULL;
3537
Py_SIZE(obj) = VISIBLE_SIZE_TP(type);
3638

3739
return (PyObject*) obj;
@@ -522,10 +524,16 @@ PyStructSequence_InitType(PyTypeObject *type, PyStructSequence_Desc *desc)
522524
Py_INCREF(type);
523525

524526
dict = type->tp_dict;
525-
PyDict_SetItemString(dict, visible_length_key,
526-
PyLong_FromLong((long) desc->n_in_sequence));
527-
PyDict_SetItemString(dict, real_length_key,
528-
PyLong_FromLong((long) n_members));
529-
PyDict_SetItemString(dict, unnamed_fields_key,
530-
PyLong_FromLong((long) n_unnamed_members));
527+
#define SET_DICT_FROM_INT(key, value) \
528+
do { \
529+
PyObject *v = PyLong_FromLong((long) value); \
530+
if (v != NULL) { \
531+
PyDict_SetItemString(dict, key, v); \
532+
Py_DECREF(v); \
533+
} \
534+
} while (0)
535+
536+
SET_DICT_FROM_INT(visible_length_key, desc->n_in_sequence);
537+
SET_DICT_FROM_INT(real_length_key, n_members);
538+
SET_DICT_FROM_INT(unnamed_fields_key, n_unnamed_members);
531539
}

Python/getargs.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,7 +1354,7 @@ convertbuffer(PyObject *arg, void **p, char **errmsg)
13541354
/* XXX for 3.x, getbuffer and convertbuffer can probably
13551355
be merged again. */
13561356
static int
1357-
getbuffer(PyObject *arg, Py_buffer *view, char**errmsg)
1357+
getbuffer(PyObject *arg, Py_buffer *view, char **errmsg)
13581358
{
13591359
void *buf;
13601360
Py_ssize_t count;
@@ -1364,8 +1364,10 @@ getbuffer(PyObject *arg, Py_buffer *view, char**errmsg)
13641364
return -1;
13651365
}
13661366
if (pb->bf_getbuffer) {
1367-
if (pb->bf_getbuffer(arg, view, 0) < 0)
1367+
if (pb->bf_getbuffer(arg, view, 0) < 0) {
1368+
*errmsg = "convertible to a buffer";
13681369
return -1;
1370+
}
13691371
if (!PyBuffer_IsContiguous(view, 'C')) {
13701372
*errmsg = "contiguous buffer";
13711373
return -1;
@@ -1374,8 +1376,10 @@ getbuffer(PyObject *arg, Py_buffer *view, char**errmsg)
13741376
}
13751377

13761378
count = convertbuffer(arg, &buf, errmsg);
1377-
if (count < 0)
1379+
if (count < 0) {
1380+
*errmsg = "convertible to a buffer";
13781381
return count;
1382+
}
13791383
PyBuffer_FillInfo(view, NULL, buf, count, 1, 0);
13801384
return 0;
13811385
}

0 commit comments

Comments
 (0)