Uploaded image for project: 'MariaDB Connector/C'
  1. MariaDB Connector/C
  2. CONC-677

Memory leak from get_default_configuration_dirs()

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • 3.3.5
    • 3.1.24, 3.3.10, 3.4.0
    • Internal
    • None
    • 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)
      

      Attachments

        Activity

          People

            georg Georg Richter
            jirislaby Jiri Slaby
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.