[CONC-495] Memory Leak found with LSan in ma_net.c Created: 2020-09-09  Updated: 2020-11-11  Resolved: 2020-09-10

Status: Closed
Project: MariaDB Connector/C
Component/s: None
Affects Version/s: 3.0.6
Fix Version/s: 3.1.10

Type: Bug Priority: Major
Reporter: Animesh Soni Assignee: Georg Richter
Resolution: Fixed Votes: 0
Labels: None
Environment:

CentOS7 docker image.



 Description   

Hey our LSan run identified a memory leak in ma_net.c file. The memory allocated on line 311 is not freed when the function returns on line 340.

You should add this code before returning "ma_net_real_write" on line 340:

#ifdef HAVE_COMPRESS
  if (net->compress)
    free((char*) packet);
#endif

This is what the LSan callstack looks like:

Direct leak of 102 byte(s) in 6 object(s) allocated from:
 
0 0x7f92a113ab78 in malloc /home/fcm/Perforce/SDK/UnixClang/dev/scripts/llvm_RELEASE_401_source/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:66
1 0x7f92a0383b55 in ma_net_real_write /mariadb-connector-c-3.0.6-src/libmariadb/ma_net.c:311
2 0x7f92a0383c57 in ma_net_flush /mariadb-connector-c-3.0.6-src/libmariadb/ma_net.c:166
3 0x7f92a0383fd8 in ma_net_write_command /mariadb-connector-c-3.0.6-src/libmariadb/ma_net.c:244
4 0x7f92a038b8ba in mthd_my_send_cmd /mariadb-connector-c-3.0.6-src/libmariadb/mariadb_lib.c:395
5 0x7f92a0392736 in net_stmt_close /mariadb-connector-c-3.0.6-src/libmariadb/mariadb_stmt.c:1324
6 0x7f92a0393333 in mysql_stmt_close /mariadb-connector-c-3.0.6-src/libmariadb/mariadb_stmt.c:1344
7 0x7f92a03aa9c7 in mysql_stmt_close_start_internal /mariadb-connector-c-3.0.6-src/libmariadb/mariadb_async.c:1509
8 0x7f92a03aeda0 in my_context_spawn /mariadb-connector-c-3.0.6-src/libmariadb/ma_context.c:201

Can I get a better context on how we could be running into this issue? Are there any known workarounds?
(we are avoiding making a custom version of the package)



 Comments   
Comment by Georg Richter [ 2020-09-10 ]

fixed - rev. 64a421295322214c827441cf824091dc874ddc6a

Comment by Animesh Soni [ 2020-09-10 ]

I just checked that the ma_net.c looks is the same for 3.0.6 and 3.1.10. Would you be able to provide context on what was triggering the leak and how was it fixed?

Or provide me a link to another JIRA issue if there was one for the leak ?

Comment by Georg Richter [ 2020-11-11 ]

It isn't the same:
https://github.com/mariadb-corporation/mariadb-connector-c/blame/v3.1.10/libmariadb/ma_net.c#L343

Generated at Thu Feb 08 03:05:44 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.