summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Dickinson <dickinsm@gmail.com>2010-07-29 21:41:59 (GMT)
committerMark Dickinson <dickinsm@gmail.com>2010-07-29 21:41:59 (GMT)
commitcf28b95800ce1480b88975270cc3a3d65dee4664 (patch)
treeb7ec9f4fd93794220e8349a261669d40e4cfef68
parent0a0fc07d371a97c35a6fc7c5a9828af3930720a1 (diff)
downloadcpython-cf28b95800ce1480b88975270cc3a3d65dee4664.zip
cpython-cf28b95800ce1480b88975270cc3a3d65dee4664.tar.gz
cpython-cf28b95800ce1480b88975270cc3a3d65dee4664.tar.bz2
Issue #9422: Fix memory leak when re-initializing a struct.Struct object.
-rw-r--r--Misc/NEWS2
-rw-r--r--Modules/_struct.c3
2 files changed, 5 insertions, 0 deletions
diff --git a/Misc/NEWS b/Misc/NEWS
index a4d301f..9eaed9a 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -1492,6 +1492,8 @@ Library
Extension Modules
-----------------
+- Issue #9422: Fix memory leak when re-initializing a struct.Struct object.
+
- Issue #7900: The getgroups(2) system call on MacOSX behaves rather oddly
compared to other unix systems. In particular, os.getgroups() does
not reflect any changes made using os.setgroups() but basicly always
diff --git a/Modules/_struct.c b/Modules/_struct.c
index d55ce0f..f85d562 100644
--- a/Modules/_struct.c
+++ b/Modules/_struct.c
@@ -1247,6 +1247,9 @@ prepare_s(PyStructObject *self)
PyErr_NoMemory();
return -1;
}
+ /* Free any s_codes value left over from a previous initialization. */
+ if (self->s_codes != NULL)
+ PyMem_FREE(self->s_codes);
self->s_codes = codes;
s = fmt;