ZABBIX BUGS AND ISSUES
  1. ZABBIX BUGS AND ISSUES
  2. ZBX-10493

Potential memory leak in case of retries in web-scenarios

    Details

      Description

      From process_httptest():

                      /* try to retrieve page several times depending on number of retries */
                      do
                      {
                              memset(&page, 0, sizeof(page));
      
                              if (CURLE_OK == (err = curl_easy_perform(easyhandle)))
                                      break;
                      }
                      while (0 < --httptest->httptest.retries);
      

      page contains dynamically-allocated write buffer data which is managed by write-callback WRITEFUNCTION2(). If it was called by the libcurl (curl_easy_perform()) but the (re)try failed then we'll lose the allocated memory (data set to 0 with memset()).

      1. main.c
        3 kB
        Viktors Tjarve

        Activity

        Hide
        Viktors Tjarve added a comment - - edited

        Attached main.c - a simple program to repeat this memory leak.

        Compile main.c with debbuging and libcurl gcc main.c -g -lcurl
        Start Valgrind sudo valgrind --tool=memcheck --read-var-info=yes --track-origins=yes --leak-check=full ./a.out
        Disconnect internet for 10 seconds and after that connect it back on. After you see an error message curl_easy_perform() failed:... stop Valgrind.

        Memory leak Valgrind test result:

        ==4664== HEAP SUMMARY:
        ==4664==     in use at exit: 2,308,362 bytes in 3,157 blocks
        ==4664==   total heap usage: 11,038 allocs, 7,881 frees, 4,591,392 bytes allocated
        ==4664== 
        ==4664== 2,072,576 bytes in 1 blocks are definitely lost in loss record 644 of 644
        ==4664==    at 0x4C2CE8E: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
        ==4664==    by 0x400D5A: zbx_strncpy_alloc (main.c:37)
        ==4664==    by 0x400E4D: WRITEFUNCTION2 (main.c:61)
        ==4664==    by 0x4E4BCCF: Curl_client_write (in /usr/lib/x86_64-linux-gnu/libcurl.so.4.3.0)
        ==4664==    by 0x4E6073F: Curl_readwrite (in /usr/lib/x86_64-linux-gnu/libcurl.so.4.3.0)
        ==4664==    by 0x4E69ACB: multi_runsingle (in /usr/lib/x86_64-linux-gnu/libcurl.so.4.3.0)
        ==4664==    by 0x4E6A270: curl_multi_perform (in /usr/lib/x86_64-linux-gnu/libcurl.so.4.3.0)
        ==4664==    by 0x4E618A2: curl_easy_perform (in /usr/lib/x86_64-linux-gnu/libcurl.so.4.3.0)
        ==4664==    by 0x401122: main (main.c:169)
        ==4664== 
        ==4664== LEAK SUMMARY:
        ==4664==    definitely lost: 2,072,576 bytes in 1 blocks
        ==4664==    indirectly lost: 0 bytes in 0 blocks
        ==4664==      possibly lost: 0 bytes in 0 blocks
        ==4664==    still reachable: 235,786 bytes in 3,156 blocks
        ==4664==         suppressed: 0 bytes in 0 blocks
        ==4664== Reachable blocks (those to which a pointer was found) are not shown.
        ==4664== To see them, rerun with: --leak-check=full --show-leak-kinds=all
        ==4664== 
        ==4664== For counts of detected and suppressed errors, rerun with: -v
        ==4664== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
        
        Show
        Viktors Tjarve added a comment - - edited Attached main.c - a simple program to repeat this memory leak. Compile main.c with debbuging and libcurl gcc main.c -g -lcurl Start Valgrind sudo valgrind --tool=memcheck --read-var-info=yes --track-origins=yes --leak-check=full ./a.out Disconnect internet for 10 seconds and after that connect it back on. After you see an error message curl_easy_perform() failed:... stop Valgrind. Memory leak Valgrind test result: ==4664== HEAP SUMMARY: ==4664== in use at exit: 2,308,362 bytes in 3,157 blocks ==4664== total heap usage: 11,038 allocs, 7,881 frees, 4,591,392 bytes allocated ==4664== ==4664== 2,072,576 bytes in 1 blocks are definitely lost in loss record 644 of 644 ==4664== at 0x4C2CE8E: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==4664== by 0x400D5A: zbx_strncpy_alloc (main.c:37) ==4664== by 0x400E4D: WRITEFUNCTION2 (main.c:61) ==4664== by 0x4E4BCCF: Curl_client_write (in /usr/lib/x86_64-linux-gnu/libcurl.so.4.3.0) ==4664== by 0x4E6073F: Curl_readwrite (in /usr/lib/x86_64-linux-gnu/libcurl.so.4.3.0) ==4664== by 0x4E69ACB: multi_runsingle (in /usr/lib/x86_64-linux-gnu/libcurl.so.4.3.0) ==4664== by 0x4E6A270: curl_multi_perform (in /usr/lib/x86_64-linux-gnu/libcurl.so.4.3.0) ==4664== by 0x4E618A2: curl_easy_perform (in /usr/lib/x86_64-linux-gnu/libcurl.so.4.3.0) ==4664== by 0x401122: main (main.c:169) ==4664== ==4664== LEAK SUMMARY: ==4664== definitely lost: 2,072,576 bytes in 1 blocks ==4664== indirectly lost: 0 bytes in 0 blocks ==4664== possibly lost: 0 bytes in 0 blocks ==4664== still reachable: 235,786 bytes in 3,156 blocks ==4664== suppressed: 0 bytes in 0 blocks ==4664== Reachable blocks (those to which a pointer was found) are not shown. ==4664== To see them, rerun with: --leak-check=full --show-leak-kinds=all ==4664== ==4664== For counts of detected and suppressed errors, rerun with: -v ==4664== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
        Hide
        Viktors Tjarve added a comment -

        Fixed in development branch svn://svn.zabbix.com/branches/dev/ZBX-10493

        Show
        Viktors Tjarve added a comment - Fixed in development branch svn://svn.zabbix.com/branches/dev/ZBX-10493
        Hide
        Sandis Neilands (Inactive) added a comment -

        Successfully tested with minor improvement in r59288. Just note that the development branch is based on 2.2 but fix version mentions only 3+.

        Also no such problem for EzTexting since there are no retries.

        Show
        Sandis Neilands (Inactive) added a comment - Successfully tested with minor improvement in r59288. Just note that the development branch is based on 2.2 but fix version mentions only 3+. Also no such problem for EzTexting since there are no retries.
        Hide
        Viktors Tjarve added a comment -

        Released in:

        • 2.2.12rc1 r59300
        • 3.0.2rc1 r59301
        • 3.1.0 r59302
        Show
        Viktors Tjarve added a comment - Released in: 2.2.12rc1 r59300 3.0.2rc1 r59301 3.1.0 r59302

          People

          • Assignee:
            Unassigned
            Reporter:
            Sandis Neilands (Inactive)
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: