[unixODBC-dev] Valgrind shows memory leak

Scott Zhong Scott.Zhong at roguewave.com
Wed Jun 4 20:34:15 BST 2014


Hi,

    Valgrind  3.8.1 shows a memory leak in unixODBC 2.3.2 after setting SQL_ATTR_ODBC_CURSORS attribute to SQL_CUR_USE_ODBC and then connecting to a data source.

Testcase snippet:

...
SQLULEN attr_cur = SQL_CUR_USE_ODBC;
SQLSetConnectAttr (hdbc, SQL_ATTR_ODBC_CURSORS, (SQLPOINTER)(SQLLEN)attr_cur, NULL);
SQLDriverConnect (hdbc, NULL, connStrIn, SQL_NTS, connStrOut, BUFFER_LEN, &connStrOutLen, SQL_DRIVER_NOPROMPT);
...

/>uname -srm
Linux 2.6.32-358.el6.x86_64 x86_64
/>cat /etc/redhat-release
Red Hat Enterprise Linux Server release 6.4 (Santiago)
/>g++ -g -I$ODBC/include testcase_unixodbc_leak.cpp -L$ODBC/lib -lodbc -lpthread
/>valgrind --leak-check=full --show-reachable=no --show-possibly-lost=no --track-origins=yes --num-callers=50 --gen-suppressions=all --xml=yes --xml-file=testcase.valgrind a.out

Valgrind leak entry:

<error>
  <unique>0xc1</unique>
  <tid>1</tid>
  <kind>Leak_DefinitelyLost</kind>
  <xwhat>
    <text>5,056 (64 direct, 4,992 indirect) bytes in 1 blocks are definitely lost in loss record 167 of 170</text>
    <leakedbytes>5056</leakedbytes>
    <leakedblocks>1</leakedblocks>
  </xwhat>
  <stack>
    <frame>
      <ip>0x4A069EE</ip>
      <obj>/usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so</obj>
      <fn>malloc</fn>
      <dir>/builddir/build/BUILD/valgrind-3.8.1/coregrind/m_replacemalloc</dir>
      <file>vg_replace_malloc.c</file>
      <line>270</line>
    </frame>
    <frame>
      <ip>0x127A65E5</ip>
    </frame>
    <frame>
      <ip>0x4C206BD</ip>
      <obj>/amd/packages/mdx/redhat/databases/unixodbc/x86_64-gcc4.1.2/lib/libodbc.so.1.0.0</obj>
      <fn>__connect_part_two</fn>
    </frame>
    <frame>
      <ip>0x4C28F74</ip>
      <obj>/amd/packages/mdx/redhat/databases/unixodbc/x86_64-gcc4.1.2/lib/libodbc.so.1.0.0</obj>
      <fn>SQLDriverConnect</fn>
    </frame>
    <frame>
      <ip>0x400F70</ip>
      <obj>/amd/tmp/scottz/a.out</obj>
      <fn>main</fn>
      <dir>/nfs/tmp/scottz</dir>
      <file>testcase_unixodbc_leak.cpp</file>
      <line>208</line>
    </frame>
  </stack>
  <suppression>
    <sname>insert_a_suppression_name_here</sname>
    <skind>Memcheck:Leak</skind>
    <sframe> <fun>malloc</fun> </sframe>
    <sframe> <obj>*</obj> </sframe>
    <sframe> <fun>__connect_part_two</fun> </sframe>
    <sframe> <fun>SQLDriverConnect</fun> </sframe>
    <sframe> <fun>main</fun> </sframe>
    <rawtext>
<![CDATA[
{
   <insert_a_suppression_name_here>
   Memcheck:Leak
   fun:malloc
   obj:*
   fun:__connect_part_two
   fun:SQLDriverConnect
   fun:main
}
]]>
    </rawtext>
  </suppression>
</error>

Regards,
Scott Z.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.unixodbc.org/pipermail/unixodbc-dev/attachments/20140604/126470a7/attachment.html>


More information about the unixODBC-dev mailing list