Bug #38693 leaked memory with blobs!
Submitted: 9 Aug 2008 17:31 Modified: 10 Nov 2008 18:22
Reporter: Shane Bester (Platinum Quality Contributor) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: DML Severity:S2 (Serious)
Version:5.0.66a, 5.1.26, 5.1.28, 6.0.7 OS:Any
Assigned to: Georgi Kodinov CPU Architecture:Any
Tags: memory leak

[9 Aug 2008 17:31] Shane Bester
Description:
some tests on a blob field let valgrind report leaked memory.

4,088 bytes in 1 blocks are possibly lost in loss record 7 of 8
0x4005400: malloc (vg_replace_malloc.c:149)
0x840DEB9: my_malloc (my_malloc.c:34)
0x81C79D1: String::real_alloc (sql_string.cc:51)
0x81B1309: Field_blob::store (sql_string.h:202)
0x813DDAB: Item::save_str_value_in_field (sql_string.h:99)
0x820AB12: fill_record (sql_base.cc:7944)
0x8208C1F: fill_record_n_invoke_before_triggers (sql_base.cc:7987)
0x8233F19: mysql_insert (sql_insert.cc:747)
0x81D724D: mysql_execute_command (sql_parse.cc:2953)
0x81DB910: mysql_parse (sql_parse.cc:5645)
0x81D424D: dispatch_command (sql_parse.cc:1137)
0x81D3DD2: do_command(THD*) (sql_parse.cc:794)

39,368 bytes in 19 blocks are definitely lost in loss record 8 of 8
0x4005400: malloc (vg_replace_malloc.c:149)
0x840DEB9: my_malloc (my_malloc.c:34)
0x81C79D1: String::real_alloc (sql_string.cc:51)
0x81B1309: Field_blob::store (sql_string.h:202)
0x813DDAB: Item::save_str_value_in_field (sql_string.h:99)
0x820AB12: fill_record (sql_base.cc:7944)
0x8208C1F: fill_record_n_invoke_before_triggers (sql_base.cc:7987)
0x8233F19: mysql_insert (sql_insert.cc:747)
0x81D724D: mysql_execute_command (sql_parse.cc:2953)
0x81DB910: mysql_parse (sql_parse.cc:5645)
0x81D424D: dispatch_command (sql_parse.cc:1137)
0x81D3DD2: do_command (sql_parse.cc:794)

How to repeat:
...
[9 Aug 2008 17:33] MySQL Verification Team
some info so i don't forget

Attachment: bug38693_more_info.txt (text/plain), 18.76 KiB.

[9 Aug 2008 19:14] MySQL Verification Team
testcase. (yeah, same testcase that used for bug #38692 !)

Attachment: bug38692.c (text/plain), 7.42 KiB.

[9 Aug 2008 20:10] MySQL Verification Team
let the testcase run a few hundred repetitions since the blob contents and length is non-deterministic
[3 Oct 2008 9:35] MySQL Verification Team
from 5.1-bugteam (5.1.30-debug) another related valgrind leak:
2,432,048 bytes in 1,340 blocks are still reachable in loss record 7 of 7
   at 0x4005400: malloc 
   by 0x858ABC8: _mymalloc (safemalloc.c:137)
   by 0x821F6CC: String::real_alloc
   by 0x81F9F52: Field_blob::store
   by 0x814F28C: Item_hex_string::save_in_field
   by 0x827643A: fill_record_n_invoke_before_triggers
   by 0x82C5165: mysql_insert
   by 0x823B5DA: mysql_execute_command
   by 0x823FBC3: mysql_parse
   by 0x8240284: dispatch_command
   by 0x8241770: do_command(THD*) (sql_parse.cc:809)
   by 0x822F947: handle_one_connection (sql_connect.cc:1115)
[15 Oct 2008 13:56] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/56274

2706 Georgi Kodinov	2008-10-15
      Bug #38693: leaked memory with blobs!
      
      If delayed insert fails to upgrade the lock it was not
      freeing the temporary memory storage used to keep
      newly constructed blob values in memory.
      Fixed by iterating over the remaining rows in the delayed
      insert rowset and freeing the blob storage for each row.
      
      No test suite because it involves concurrent delayed inserts 
      on a table and cannot easily be made deterministic. 
      
      Added a correct valgrind suppression for Fedora 9.
[24 Oct 2008 8:42] Bugs System
Pushed into 5.0.72  (revid:kgeorge@mysql.com-20081015135552-q9xwufjz42vd3kgw) (version source revid:kgeorge@mysql.com-20081015135552-q9xwufjz42vd3kgw) (pib:5)
[24 Oct 2008 20:19] Paul DuBois
Noted in 5.0.72 changelog.

If delayed insert failed to upgrade the lock, it did not free the
temporary memory storage used to keep newly constructed BLOB values
in memory, resulting in a memory leak.

Setting report to NDI pending push into 5.1.x, 6.0.x.
[10 Nov 2008 10:51] Bugs System
Pushed into 6.0.8-alpha  (revid:kgeorge@mysql.com-20081015135552-q9xwufjz42vd3kgw) (version source revid:kgeorge@mysql.com-20081021085131-2v86qbmg27inufx2) (pib:5)
[10 Nov 2008 11:35] Bugs System
Pushed into 5.1.30  (revid:kgeorge@mysql.com-20081015135552-q9xwufjz42vd3kgw) (version source revid:kgeorge@mysql.com-20081021075503-bsoq43pkwy82ksuv) (pib:5)
[10 Nov 2008 18:22] Paul DuBois
Note in 51..31, 6.0.8 changelogs.
[11 Nov 2008 16:30] Paul DuBois
6.0.9 changelog, not 6.0.8.
[19 Jan 2009 11:22] Bugs System
Pushed into 5.1.31-ndb-6.2.17 (revid:tomas.ulin@sun.com-20090119095303-uwwvxiibtr38djii) (version source revid:tomas.ulin@sun.com-20090108105244-8opp3i85jw0uj5ib) (merge vers: 5.1.31-ndb-6.2.17) (pib:6)
[19 Jan 2009 13:00] Bugs System
Pushed into 5.1.31-ndb-6.3.21 (revid:tomas.ulin@sun.com-20090119104956-guxz190n2kh31fxl) (version source revid:tomas.ulin@sun.com-20090119104956-guxz190n2kh31fxl) (merge vers: 5.1.31-ndb-6.3.21) (pib:6)
[19 Jan 2009 16:06] Bugs System
Pushed into 5.1.31-ndb-6.4.1 (revid:tomas.ulin@sun.com-20090119144033-4aylstx5czzz88i5) (version source revid:tomas.ulin@sun.com-20090119144033-4aylstx5czzz88i5) (merge vers: 5.1.31-ndb-6.4.1) (pib:6)