Search code examples
sql-serverlinuxdatabasememory-leaksvalgrind

MSSQL memory leak issue during SQLDriverConnect (in /usr/lib64/libodbc.so.2.0.0)


I use valgrind to check the memory leak and I see lots of repeated messages like below:

==29757== HEAP SUMMARY:
==29757== in use at exit: 62,472 bytes in 850 blocks
==29757== total heap usage: 7,597 allocs, 6,747 frees, 2,132,087 bytes allocated
    ==29757==
    ==29757== 1 bytes in 1 blocks are still reachable in loss record 1 of 767
    ==29757== at 0x4C29F73: malloc (vg_replace_malloc.c:309)
    ==29757== by 0x6020AF9: strdup (in /usr/lib64/libc-2.17.so)
    ==29757== by 0x5559B0F: ??? (in /usr/lib64/libodbc.so.2.0.0)
    ==29757== by 0x5559DF9: ??? (in /usr/lib64/libodbc.so.2.0.0)
    ==29757== by 0x551F0C2: SQLDriverConnect (in /usr/lib64/libodbc.so.2.0.0)
    ==29757== by 0x41125B: Database::init(std::string const&) 

    ==29757== 1 bytes in 1 blocks are still reachable in loss record 2 of 767
    ==29757== at 0x4C29F73: malloc (vg_replace_malloc.c:309)
    ==29757== by 0x6020AF9: strdup (in /usr/lib64/libc-2.17.so)
    ==29757== by 0x5559ABA: ??? (in /usr/lib64/libodbc.so.2.0.0)
    ==29757== by 0x5559DF9: ??? (in /usr/lib64/libodbc.so.2.0.0)
    ==29757== by 0x551F0C2: SQLDriverConnect (in /usr/lib64/libodbc.so.2.0.0)
    ==29757== by 0x41125B: Database::init(std::string const&) 

I have also checked

https://github.com/Azure/unixODBC-MSSQL/blob/master/DriverManager/SQLDriverConnect.c

I don't see why there is a memory leak due to SQLDriverConnect

I wonder why I can see so many of the repetitive messages.


Solution

  • These reports are showing still reachable memory. For many programs, such 'still reachable' memory is not a problem, as they (on purpose) do not release all the allocated memory before exiting, as this would be useless work.

    The 2 reports shown above are very similar but considered different by valgrind because the stack trace is slightly different: you have one of the program counters that differs.