Uploaded image for project: 'ZABBIX BUGS AND ISSUES'
  1. ZABBIX BUGS AND ISSUES
  2. ZBX-11720

Memory leak in zabbix_agentd breaks vfs.fs.size, vfs.fs.inode and vfs.dir.size items if compiled with LeakSanitizer

    • Sprint 25, Sprint 26
    • 2

      1. Compile Zabbix with GCC 6.2 with "-fsanitize=leak" option:

      $ CFLAGS="-g -O2 -fsanitize=leak" ./configure --enable-server --enable-proxy --enable-agent --enable-ipv6 --with-net-snmp --with-unixodbc --with-libxml2 --with-libcurl --with-openipmi --with-ldap --with-postgresql --with-openssl --prefix=`pwd`
      

      2. Create an item which is checked by starting a separate thread on the agent - it could be 'vfs.fs.size', 'vfs.fs.inode' or 'vfs.dir.size'.
      3. Observe in zabbix_agentd.log:

         512:20170120:130846.116 Requested [vfs.dir.size[/home/zabbix34/ZBXNEXT-491/ZBXNEXT-491-2]]
         512:20170120:130846.116 In zbx_execute_threaded_metric() key:'vfs.dir.size'
         554:20170120:130846.118 executing in data process for key:'vfs.dir.size'
      
      =================================================================
      ==554==ERROR: LeakSanitizer: detected memory leaks
      
      Direct leak of 24 byte(s) in 1 object(s) allocated from:
          #0 0x7fd3022fdc7f in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/liblsan.so.0+0xcc7f)
          #1 0x55fe97829677 in zbx_malloc2 /home/zabbix34/ZBXNEXT-491/trunk/src/libs/zbxcommon/misc.c:467
      
      SUMMARY: LeakSanitizer: 24 byte(s) leaked in 1 allocation(s).
         512:20170120:130846.168 End of zbx_execute_threaded_metric():1 'Data gathering process terminated with error.'
         512:20170120:130846.168 Sending back [ZBX_NOTSUPPORTED: Data gathering process terminated with error.]
      

      4. To confirm where the leak comes from, make a small change and recompile:

      Index: src/zabbix_agent/zabbix_agentd.c
      ===================================================================
      --- src/zabbix_agent/zabbix_agentd.c	(revision 65211)
      +++ src/zabbix_agent/zabbix_agentd.c	(working copy)
      @@ -953,7 +953,7 @@
       	{
       		zbx_thread_args_t	*thread_args;
       
      -		thread_args = (zbx_thread_args_t *)zbx_malloc(NULL, sizeof(zbx_thread_args_t));
      +		thread_args = (zbx_thread_args_t *)malloc(sizeof(zbx_thread_args_t));
       
       		if (FAIL == get_process_info_by_thread(i + 1, &thread_args->process_type, &thread_args->process_num))
       		{
      

      5. Now in zabbix_agentd.log:

        1361:20170120:132246.341 Requested [vfs.dir.size[/home/zabbix34/ZBXNEXT-491/ZBXNEXT-491-2]]
        1361:20170120:132246.341 In zbx_execute_threaded_metric() key:'vfs.dir.size'
        1504:20170120:132246.342 executing in data process for key:'vfs.dir.size'
      
      =================================================================
      ==1504==ERROR: LeakSanitizer: detected memory leaks
      
      Direct leak of 96 byte(s) in 4 object(s) allocated from:
          #0 0x7fbb1ca4ac7f in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/liblsan.so.0+0xcc7f)
          #1 0x5641e090a140 in MAIN_ZABBIX_ENTRY /home/zabbix34/ZBXNEXT-491/trunk/src/zabbix_agent/zabbix_agentd.c:956
      
      SUMMARY: LeakSanitizer: 96 byte(s) leaked in 4 allocation(s).
        1361:20170120:132246.371 End of zbx_execute_threaded_metric():1 'Data gathering process terminated with error.'
        1361:20170120:132246.371 Sending back [ZBX_NOTSUPPORTED: Data gathering process terminated with error.]
      

            andris Andris Mednis
            andris Andris Mednis
            Team A
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: