This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: memory leaks in error handling in csv and pickle modules
Type: Stage: resolved
Components: Extension Modules Versions:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: miss-islington, pablogsal, serhiy.storchaka, sir-sigurd
Priority: normal Keywords: patch

Created on 2018-08-13 16:53 by sir-sigurd, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 8756 merged sir-sigurd, 2018-08-13 16:54
PR 8779 merged miss-islington, 2018-08-16 04:28
PR 8780 merged miss-islington, 2018-08-16 04:28
PR 8785 merged sir-sigurd, 2018-08-16 12:37
PR 8788 merged sir-sigurd, 2018-08-16 17:02
Messages (9)
msg323487 - (view) Author: Sergey Fedoseev (sir-sigurd) * Date: 2018-08-13 16:53
There are memory leaks in csv and pickle modules caused by incautious usage of PyMem_Resize().

See GitHub PR.
msg323492 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2018-08-13 20:37
Hi and thank you for the report. Could you elaborate a bit more on how/where the leak happens? This will help when reviewing the Pull Request. Thanks!
msg323506 - (view) Author: Sergey Fedoseev (sir-sigurd) * Date: 2018-08-14 10:10
> Could you elaborate a bit more on how/where the leak happens?

It happens when PyMem_Resize() fails. It was used like this:

Py_UCS4 *field = self->field;
self->field = PyMem_Resize(field, Py_UCS4, self->field_size);

The last statement changes both self->field and field (macro magic!), so in the case PyMem_Resize() fails, previously allocated memory can't be freed.
msg323589 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-08-16 04:27
New changeset 67b9cc8e6072a919d2ed7e7ecc8124c8acfb3733 by Serhiy Storchaka (Sergey Fedoseev) in branch 'master':
bpo-34395: Fix memory leaks caused by incautious usage of PyMem_Resize(). (GH-8756)
https://github.com/python/cpython/commit/67b9cc8e6072a919d2ed7e7ecc8124c8acfb3733
msg323590 - (view) Author: miss-islington (miss-islington) Date: 2018-08-16 04:53
New changeset 962051eeb0ba486b8ffe4082779b4fa432e3dfb2 by Miss Islington (bot) in branch '3.7':
bpo-34395: Fix memory leaks caused by incautious usage of PyMem_Resize(). (GH-8756)
https://github.com/python/cpython/commit/962051eeb0ba486b8ffe4082779b4fa432e3dfb2
msg323591 - (view) Author: miss-islington (miss-islington) Date: 2018-08-16 04:57
New changeset b14ab447ee3f47d479d899b4001d870569a76c44 by Miss Islington (bot) in branch '3.6':
bpo-34395: Fix memory leaks caused by incautious usage of PyMem_Resize(). (GH-8756)
https://github.com/python/cpython/commit/b14ab447ee3f47d479d899b4001d870569a76c44
msg323635 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-08-17 05:36
New changeset ae1f0127298b1193618062fd0c8a3b434656e780 by Serhiy Storchaka (Sergey Fedoseev) in branch '2.7':
bpo-34395: Fix memory leaks caused by incautious usage of PyMem_Realloc(). (GH-8785)
https://github.com/python/cpython/commit/ae1f0127298b1193618062fd0c8a3b434656e780
msg324058 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-08-25 10:42
New changeset 90555eca44a19c743d39b7fd2e05f7bc37fb5cb8 by Serhiy Storchaka (Sergey Fedoseev) in branch 'master':
bpo-34395: Don't free allocated memory on realloc fail in load_mark() in _pickle.c. (GH-8788)
https://github.com/python/cpython/commit/90555eca44a19c743d39b7fd2e05f7bc37fb5cb8
msg324059 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-08-25 10:42
Thank you for your report and fix Sergey.
History
Date User Action Args
2022-04-11 14:59:04adminsetgithub: 78576
2018-08-25 10:42:58serhiy.storchakasetstatus: open -> closed
resolution: fixed
messages: + msg324059

stage: patch review -> resolved
2018-08-25 10:42:02serhiy.storchakasetmessages: + msg324058
2018-08-17 05:36:27serhiy.storchakasetmessages: + msg323635
2018-08-16 17:02:32sir-sigurdsetpull_requests: + pull_request8262
2018-08-16 12:37:14sir-sigurdsetpull_requests: + pull_request8258
2018-08-16 04:57:07miss-islingtonsetmessages: + msg323591
2018-08-16 04:53:03miss-islingtonsetnosy: + miss-islington
messages: + msg323590
2018-08-16 04:28:26miss-islingtonsetpull_requests: + pull_request8254
2018-08-16 04:28:15miss-islingtonsetpull_requests: + pull_request8253
2018-08-16 04:27:52serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg323589
2018-08-14 10:10:26sir-sigurdsetmessages: + msg323506
2018-08-13 20:37:19pablogsalsetnosy: + pablogsal
messages: + msg323492
2018-08-13 16:54:20sir-sigurdsetkeywords: + patch
stage: patch review
pull_requests: + pull_request8232
2018-08-13 16:53:22sir-sigurdcreate