[CONC-677] Memory leak from get_default_configuration_dirs() Created: 2023-11-23  Updated: 2023-11-23

Status: Open
Project: MariaDB Connector/C
Component/s: Internal
Affects Version/s: 3.3.5
Fix Version/s: None

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

openSUSE Tumbleweed x86_64



 Description   

In ma_default.c, get_default_configuration_dirs() allocates memory which is returned to mariadb_lib.c's mysql_once_init(). But there are few issues:

  • in case something fails in get_default_configuration_dirs(), NULL is returned but the memory is not freed
  • add_cfg_dir() in get_default_configuration_dirs() allocates more memory using strdup()
  • mysql_once_init() completely ignores the return value (the allocated memory), so the memory is never freed.

valgrind reports this:

==3220== 5 bytes in 1 blocks are still reachable in loss record 1 of 4
==3220==    at 0x4843794: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==3220==    by 0x4CCCB2D: strdup (strdup.c:42)
==3220==    by 0x488F68A: add_cfg_dir (ma_default.c:57)
==3220==    by 0x488F736: get_default_configuration_dirs (ma_default.c:121)
==3220==    by 0x4893701: mysql_once_init (mariadb_lib.c:4298)
==3220==    by 0x4CBA28E: __pthread_once_slow (pthread_once.c:116)
==3220==    by 0x489328E: mysql_init (mariadb_lib.c:1261)
==3220==    by 0x10A3B3: SQLConn::openDB() (db.cpp:91)
==3220==    by 0x10AE6B: main (db.cpp:233)
==3220== 
==3220== 11 bytes in 1 blocks are still reachable in loss record 2 of 4
==3220==    at 0x4843794: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==3220==    by 0x4CCCB2D: strdup (strdup.c:42)
==3220==    by 0x488F68A: add_cfg_dir (ma_default.c:57)
==3220==    by 0x488F749: get_default_configuration_dirs (ma_default.c:123)
==3220==    by 0x4893701: mysql_once_init (mariadb_lib.c:4298)
==3220==    by 0x4CBA28E: __pthread_once_slow (pthread_once.c:116)
==3220==    by 0x489328E: mysql_init (mariadb_lib.c:1261)
==3220==    by 0x10A3B3: SQLConn::openDB() (db.cpp:91)
==3220==    by 0x10AE6B: main (db.cpp:233)
==3220== 
==3220== 56 bytes in 1 blocks are still reachable in loss record 3 of 4
==3220==    at 0x484874F: calloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==3220==    by 0x488F714: get_default_configuration_dirs (ma_default.c:81)
==3220==    by 0x4893701: mysql_once_init (mariadb_lib.c:4298)
==3220==    by 0x4CBA28E: __pthread_once_slow (pthread_once.c:116)
==3220==    by 0x489328E: mysql_init (mariadb_lib.c:1261)
==3220==    by 0x10A3B3: SQLConn::openDB() (db.cpp:91)
==3220==    by 0x10AE6B: main (db.cpp:233)


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