Bug #79887 Python connector with C extension leaks memory if used to insert unicode strings
Submitted: 8 Jan 2016 10:39 Modified: 28 Jul 2017 2:33
Reporter: Andrea Calligaris Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / Python Severity:S1 (Critical)
Version:2.1.3 OS:CentOS (6.6)
Assigned to: CPU Architecture:Any
Tags: python connector cext C extension memory leak

[8 Jan 2016 10:39] Andrea Calligaris
Description:
Hi,

we tried to enable the C extension with the python connector 2.1.3.
Unfortunately it seems to leak memory when executing insert statements with unicode strings (see snippet).

There is no leak when `use_pure=True` (e.g. C extension is disabled).

How to repeat:
import mysql.connector

dbconn = mysql.connector.connect(user=MYSQL_USER, password=MYSQL_PASS,
                                 database=MYSQL_DB, host=MYSQL_HOST,
                                 port=MYSQL_PORT, charset='utf8',
                                 autocommit=True, use_pure=False)

cursor = dbconn.cursor()
cursor.execute("CREATE TABLE TestTbl (Id int, Name varchar(45), PRIMARY KEY(id));")

row = [1, u'JustAString']
for i in xrange(0, 1024*1024*1024):
    row[0] += 1
    cursor.execute("INSERT INTO TestTbl (Id, Name) VALUES (%s, %s)", row)
[25 Feb 2016 11:24] Chiranjeevi Battula
Hello  Andrea Calligaris,

Thank you for the bug report and test case.
Verified this behavior on Python 2.7.10 and MySQL Connector/Python 2.1.3.

Thanks,
Chiranjeevi.
[28 Jul 2017 2:33] Paul DuBois
Posted by developer:
 
Fixed in 2.1.7.

The C Extension leaked memory if used to execute INSERT statements
that inserted Unicode strings.