[CONC-442] C application memory consumption grows endlessly if the same DB conection has been used for a long time Created: 2019-10-10  Updated: 2020-05-07

Status: Open
Project: MariaDB Connector/C
Component/s: None
Affects Version/s: 2.3.4, 3.1.7
Fix Version/s: None

Type: Bug Priority: Major
Reporter: YURII KANTONISTOV Assignee: Georg Richter
Resolution: Unresolved Votes: 0
Labels: None
Environment:

Any



 Description   

In a MariaDB client memory allocation routine:

gptr alloc_root(MEM_ROOT *mem_root, size_t Size)
...
get_size= MAX(Size+ALIGN_SIZE(sizeof(USED_MEM)),
(mem_root->block_size & ~1) * (mem_root->block_num >> 2));

The problem is that if DB connection is open for a long time e.g. weeks, block_num incremented with every alloc_root call an gets quite high and get_size becomes bigger and bigger reaching finally 4GB for 32bit processes causing MariaDB application shutdown.

Workarounded it by changing alloc_root code to:

get_size= MAX(Size+ALIGN_SIZE(sizeof(MA_USED_MEM)),
(mem_root->block_size & ~1) * 1024 );

Looks working but not sure whether it is a correct solution.



 Comments   
Comment by Georg Richter [ 2019-10-11 ]

Thanks for your bug report.
Can you please check with a more recent version (e.g. current 3.1) if the problem still exists?
MariaDB Connector/C 2.x is eoled and will not get any bugfixes anymore.

Comment by YURII KANTONISTOV [ 2019-10-11 ]

Same problem exists in the latest 3.1.4 - block_num is always incremented and
malloc_root allocates more and more memory finally hitting 32bit application limit of 4GB:

c:\tools\mariadb-connector-c-3.1.4-src\mariadb-connector-c-3.1.4-src\libmariadb>grep -n block_num *
ma_alloc.c:30: mem_root->block_num= 4;
ma_alloc.c:88: (mem_root->block_size & ~1) * (mem_root->block_num >> 2));
ma_alloc.c:96: mem_root->block_num++;

Comment by YURII KANTONISTOV [ 2020-05-07 ]

Same behavior with the connector version 3.1.7.

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