classification
Title: Memory leak in _ssl.c
Type: resource usage Stage: resolved
Components: IO Versions: Python 3.4, Python 3.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: georg.brandl Nosy List: Daniel.Sommermann, christian.heimes, georg.brandl, jcea, pitrou, python-dev
Priority: normal Keywords: patch

Created on 2012-09-19 22:01 by Daniel.Sommermann, last changed 2012-09-24 05:46 by python-dev. This issue is now closed.

Files
File name Uploaded Description Edit
npn_memfix.patch christian.heimes, 2012-09-20 01:02 review
Messages (7)
msg170774 - (view) Author: Daniel Sommermann (Daniel.Sommermann) Date: 2012-09-19 22:01
I noticed that the function _set_npn_protocols() has the following line:

self->npn_protocols = PyMem_Malloc(protos.len);

There is no check to see if self->npn_protocols is already allocated. Thus, multiple calls to _set_npn_protocols() will leak memory. There should be a check to see if it is non-null and free the memory pointed to by self->npn_protocols before the malloc unless I am missing something.
msg170779 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2012-09-20 01:02
You are right. I did some testing and the function indeed leaks memory. The attached patch fixes the issue for me.
msg170793 - (view) Author: Daniel Sommermann (Daniel.Sommermann) Date: 2012-09-20 07:01
This patch looks good to me (it's exactly how I fixed it in my local build), although I'm not sure how to approve your patch so you can push it to the upstream.
msg170796 - (view) Author: Roundup Robot (python-dev) Date: 2012-09-20 10:43
New changeset 2bdc8c8ea42e by Christian Heimes in branch 'default':
Issue #15977: Fix memory leak in Modules/_ssl.c when the function _set_npn_protocols() is called multiple times
http://hg.python.org/cpython/rev/2bdc8c8ea42e
msg170797 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2012-09-20 10:49
Georg, here is another candidate for the new release candidate.

Daniel, two equal patches are good enough as a patch review. The fix is simple and straight forward, too. Thanks for your report!
msg170960 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2012-09-22 06:56
Picked.
msg171098 - (view) Author: Roundup Robot (python-dev) Date: 2012-09-24 05:46
New changeset 4cf53684e14e by Christian Heimes in branch 'default':
Issue #15977: Fix memory leak in Modules/_ssl.c when the function _set_npn_protocols() is called multiple times
http://hg.python.org/cpython/rev/4cf53684e14e
History
Date User Action Args
2012-09-24 05:46:48python-devsetmessages: + msg171098
2012-09-22 06:56:20georg.brandlsetstatus: pending -> closed

messages: + msg170960
2012-09-20 10:49:38christian.heimessetstatus: open -> pending

assignee: georg.brandl

nosy: + georg.brandl
messages: + msg170797
resolution: fixed
stage: patch review -> resolved
2012-09-20 10:43:56python-devsetnosy: + python-dev
messages: + msg170796
2012-09-20 07:01:14Daniel.Sommermannsetmessages: + msg170793
2012-09-20 03:01:50jceasettype: resource usage
stage: patch review
2012-09-20 03:01:25jceasetnosy: + jcea

type: resource usage -> (no value)
stage: patch review -> (no value)
2012-09-20 01:02:34christian.heimessetfiles: + npn_memfix.patch

type: resource usage

keywords: + patch
nosy: + christian.heimes
messages: + msg170779
stage: patch review
2012-09-19 22:01:59Daniel.Sommermanncreate