<p>I have added valgrind instrumentation directives to <strong>q_malloc</strong>, but I suspect memcheck doesn't know how to check shared memory accessed be several processes.</p>
<p>for pkg memory, it gives correct reports such as:</p>
<pre><code>==134243== 13,584 bytes in 104 blocks are definitely lost in loss record 438 of 451
==134243==    at 0x64E0D0: qm_detach_free (q_malloc.c:270)
==134243==    by 0x64EBC7: qm_malloc (q_malloc.c:415)
==134243==    by 0x70A26C: addstr (cfg.lex:1382)
==134243==    by 0x70A1DB: addchar (cfg.lex:1366)
==134243==    by 0x70653D: yylex (cfg.lex:1170)
==134243==    by 0x71305D: yyparse (cfg.tab.c:4775)
==134243==    by 0x425A8C: main (main.c:2137)
</code></pre>
<p>(this "leak" is expected though)</p>
<p>but for any operation in shm, it gives (only, and tons of) inconsistent reports such as:</p>
<pre><code>==134284== Invalid read of size 4
==134284==    at 0x4C94D2: atomic_get_and_set_int (atomic_x86.h:223)
==134284==    by 0x4C9677: futex_release (futexlock.h:134)
==134284==    by 0x4EEAFB: tcpconn_do_send (tcp_main.c:2548)
==134284==    by 0x4EBEC9: tcpconn_send_put (tcp_main.c:2289)
==134284==    by 0x4E9733: tcp_send (tcp_main.c:2046)
==134284==    by 0x6E2F612: msg_send_buffer (forward.h:218)
==134284==    by 0x6E3204F: send_pr_buffer (t_funcs.c:70)
==134284==    by 0x6DD4A5F: _reply_light (t_reply.c:554)
==134284==    by 0x6DD56C6: _reply (t_reply.c:659)
==134284==    by 0x6DDC7D5: t_reply (t_reply.c:1552)
==134284==    by 0x6DF1E02: w_t_reply (tm.c:1246)
==134284==    by 0x6DF7EE4: w_t_reply_wrp (tm.c:2041)
==134284==  Address 0x9691ce0 is not stack'd, malloc'd or (recently) free'd
</code></pre>
<p>I've pushed the work in this branch: <a href="https://github.com/kamailio/kamailio/tree/tmp/valgrind">https://github.com/kamailio/kamailio/tree/tmp/valgrind</a></p>
<p>Do you have any info on whether memcheck can deal with shared pools?</p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/kamailio/kamailio/issues/949#issuecomment-282311321">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AF36ZdrcfYRehn2YCIuzWypI2a6q_SRrks5rfu-2gaJpZM4LuZds">mute the thread</a>.<img alt="" height="1" src="https://github.com/notifications/beacon/AF36ZSSo7_mHp26VvNgwI6SJWo2WHWRGks5rfu-2gaJpZM4LuZds.gif" width="1" /></p>
<div itemscope itemtype="http://schema.org/EmailMessage">
<div itemprop="action" itemscope itemtype="http://schema.org/ViewAction">
  <link itemprop="url" href="https://github.com/kamailio/kamailio/issues/949#issuecomment-282311321"></link>
  <meta itemprop="name" content="View Issue"></meta>
</div>
<meta itemprop="description" content="View this Issue on GitHub"></meta>
</div>

<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/kamailio/kamailio","title":"kamailio/kamailio","subtitle":"GitHub repository","main_image_url":"https://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png","avatar_image_url":"https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png","action":{"name":"Open in GitHub","url":"https://github.com/kamailio/kamailio"}},"updates":{"snippets":[{"icon":"PERSON","message":"@camilleoudot in #949: I have added valgrind instrumentation directives to **q_malloc**, but I suspect memcheck doesn't know how to check shared memory accessed be several processes.\r\n\r\nfor pkg memory, it gives correct reports such as:\r\n```\r\n==134243== 13,584 bytes in 104 blocks are definitely lost in loss record 438 of 451\r\n==134243==    at 0x64E0D0: qm_detach_free (q_malloc.c:270)\r\n==134243==    by 0x64EBC7: qm_malloc (q_malloc.c:415)\r\n==134243==    by 0x70A26C: addstr (cfg.lex:1382)\r\n==134243==    by 0x70A1DB: addchar (cfg.lex:1366)\r\n==134243==    by 0x70653D: yylex (cfg.lex:1170)\r\n==134243==    by 0x71305D: yyparse (cfg.tab.c:4775)\r\n==134243==    by 0x425A8C: main (main.c:2137)\r\n```\r\n(this \"leak\" is expected though)\r\n\r\nbut for any operation in shm, it gives (only, and tons of) inconsistent reports such as:\r\n```\r\n==134284== Invalid read of size 4\r\n==134284==    at 0x4C94D2: atomic_get_and_set_int (atomic_x86.h:223)\r\n==134284==    by 0x4C9677: futex_release (futexlock.h:134)\r\n==134284==    by 0x4EEAFB: tcpconn_do_send (tcp_main.c:2548)\r\n==134284==    by 0x4EBEC9: tcpconn_send_put (tcp_main.c:2289)\r\n==134284==    by 0x4E9733: tcp_send (tcp_main.c:2046)\r\n==134284==    by 0x6E2F612: msg_send_buffer (forward.h:218)\r\n==134284==    by 0x6E3204F: send_pr_buffer (t_funcs.c:70)\r\n==134284==    by 0x6DD4A5F: _reply_light (t_reply.c:554)\r\n==134284==    by 0x6DD56C6: _reply (t_reply.c:659)\r\n==134284==    by 0x6DDC7D5: t_reply (t_reply.c:1552)\r\n==134284==    by 0x6DF1E02: w_t_reply (tm.c:1246)\r\n==134284==    by 0x6DF7EE4: w_t_reply_wrp (tm.c:2041)\r\n==134284==  Address 0x9691ce0 is not stack'd, malloc'd or (recently) free'd\r\n```\r\n\r\nI've pushed the work in this branch: https://github.com/kamailio/kamailio/tree/tmp/valgrind\r\n\r\nDo you have any info on whether memcheck can deal with shared pools?"}],"action":{"name":"View Issue","url":"https://github.com/kamailio/kamailio/issues/949#issuecomment-282311321"}}}</script>