diff --git a/Misc/NEWS b/Misc/NEWS index 833d0deef675..95051913b6ee 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -323,6 +323,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 c1db286b051e..74d846a42c09 100644 --- a/Modules/_struct.c +++ b/Modules/_struct.c @@ -1233,6 +1233,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;