From: Amaury Forgeot d'Arc <amauryfa@gmail.com>
Date: Fri, 22 Aug 2008 22:05:20 +0000 (+0000)
Subject: #3650: fix a reference leak in bytes.split('x')
X-Git-Tag: v3.0rc1~190
X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=20443f30436cd93b491286a596063a9ede832467;p=python

#3650: fix a reference leak in bytes.split('x')
Actually the same as r65785, but trunk only has bytearray.
---

diff --git a/Misc/NEWS b/Misc/NEWS
index 89ffdc1a07..3173fcb71c 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,8 @@ What's New in Python 3.0 release candidate 1
 Core and Builtins
 -----------------
 
+- Issue #3650: Fixed a reference leak in bytes.split('x').
+
 Library
 -------
 
diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c
index 52479ca41d..bfb4ff8fd3 100644
--- a/Objects/bytesobject.c
+++ b/Objects/bytesobject.c
@@ -1163,8 +1163,11 @@ string_split(PyBytesObject *self, PyObject *args)
 		PyBuffer_Release(&vsub);
 		return NULL;
 	}
-	else if (n == 1)
-		return split_char(self, len, sub[0], maxsplit);
+	else if (n == 1) {
+		list = split_char(self, len, sub[0], maxsplit);
+		PyBuffer_Release(&vsub);
+		return list;
+	}
 
 	list = PyList_New(PREALLOC_SIZE(maxsplit));
 	if (list == NULL) {
@@ -1379,8 +1382,11 @@ string_rsplit(PyBytesObject *self, PyObject *args)
 		PyBuffer_Release(&vsub);
 		return NULL;
 	}
-	else if (n == 1)
-		return rsplit_char(self, len, sub[0], maxsplit);
+	else if (n == 1) {
+		list = rsplit_char(self, len, sub[0], maxsplit);
+		PyBuffer_Release(&vsub);
+		return list;
+	}
 
 	list = PyList_New(PREALLOC_SIZE(maxsplit));
 	if (list == NULL) {