<html>
  <head>
    <meta content="text/html; charset=windows-1252"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <tt>The generic DB backend from OpenSIPS is built to re-use any
      connection. Just to make it clear, from a network point of view,
      SQLite is connection-less, since, after all, it's just a bunch of
      files with some libraries that work on top of them.<br>
      <br>
      Regarding the leak, sqlite3_open() is not an OpenSIPS function,
      and it looks to be called only in the init phase, which is a good
      thing at least. If we want to get it fixed, we should first
      confirm it, then escalate it to the SQLite project.</tt><br>
    <pre class="moz-signature" cols="72">Liviu Chircu
OpenSIPS Developer
<a class="moz-txt-link-freetext" href="http://www.opensips-solutions.com">http://www.opensips-solutions.com</a></pre>
    <div class="moz-cite-prefix">On 15.04.2016 19:32, Rodrigo Pimenta
      Carvalho wrote:<br>
    </div>
    <blockquote
cite="mid:BLUPR02MB165268D5AD64B1A4B8A1E0F8B5680@BLUPR02MB1652.namprd02.prod.outlook.com"
      type="cite">
      <meta http-equiv="Content-Type" content="text/html;
        charset=windows-1252">
      <style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
      <div id="divtagdefaultwrapper"
style="font-size:12pt;color:#000000;background-color:#FFFFFF;font-family:Calibri,Arial,Helvetica,sans-serif;">
        <p>Hi Liviu.</p>
        <p><br>
        </p>
        <p>Thank you very much for answering my question and for these
          hints.</p>
        <p>I will talk to my team about to consider using OpenSIPS 2.2+.
          I will also read more about "-M" flag and see how should I use
          it.</p>
        <p><br>
        </p>
        <p>I have one more question:</p>
        <p>Is there one more opened connection to the Sqlite database
          every time when my script executes a qvp_db_query?  If yes,
          these connections remain opened or it is closed immediately
          after the query terminates?</p>
        <p>What I need to know is if the OpenSIPS is creating too many
          connections to the database.</p>
        <p><br>
        </p>
        <p>Today, with valgrind I saw this log:</p>
        <p><br>
        </p>
        <p>==501== 167,528 (848 direct, 166,680 indirect) bytes in 1
          blocks are definitely lost in loss record 425 of 428<br>
          ==501==    at 0x4C2AB80: malloc (in
          /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)<br>
          ==501==    by 0x738EDC6: ??? (in
          /usr/lib/x86_64-linux-gnu/libsqlite3.so.0.8.6)<br>
          ==501==    by 0x7369569: ??? (in
          /usr/lib/x86_64-linux-gnu/libsqlite3.so.0.8.6)<br>
          ==501==    by 0x7371C47: ??? (in
          /usr/lib/x86_64-linux-gnu/libsqlite3.so.0.8.6)<br>
          ==501==    by 0x7371C6C: ??? (in
          /usr/lib/x86_64-linux-gnu/libsqlite3.so.0.8.6)<br>
          ==501==    by 0x73EF012: ??? (in
          /usr/lib/x86_64-linux-gnu/libsqlite3.so.0.8.6)<br>
          ==501==    by 0x7132D9A: db_sqlite_connect (my_con.c:62)<br>
          ==501==    by 0x7133314: db_sqlite_new_connection
          (my_con.c:134)<br>
          ==501==    by 0x5693A3: db_do_init (db.c:309)<br>
          ==501==    by 0x7A5F606: register_udomain (dlist.c:655)<br>
          ==501==    by 0x7C9014D: domain_fixup (reg_mod.c:386)<br>
          ==501==    by 0x7C9014D: registrar_fixup (reg_mod.c:421)<br>
          ==501==    by 0x4A731B: fix_actions (route.c:459)<br>
          ==501== <br>
          ==501== 169,216 (848 direct, 168,368 indirect) bytes in 1
          blocks are definitely lost in loss record 426 of 428<br>
          ==501==    at 0x4C2AB80: malloc (in
          /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)<br>
          ==501==    by 0x738EDC6: ??? (in
          /usr/lib/x86_64-linux-gnu/libsqlite3.so.0.8.6)<br>
          ==501==    by 0x7369569: ??? (in
          /usr/lib/x86_64-linux-gnu/libsqlite3.so.0.8.6)<br>
          ==501==    by 0x7371C47: ??? (in
          /usr/lib/x86_64-linux-gnu/libsqlite3.so.0.8.6)<br>
          ==501==    by 0x7371C6C: ??? (in
          /usr/lib/x86_64-linux-gnu/libsqlite3.so.0.8.6)<br>
          ==501==    by 0x73EF012: ??? (in
          /usr/lib/x86_64-linux-gnu/libsqlite3.so.0.8.6)<br>
          ==501==    by 0x7132D9A: db_sqlite_connect (my_con.c:62)<br>
          ==501==    by 0x7133314: db_sqlite_new_connection
          (my_con.c:134)<br>
          ==501==    by 0x5693A3: db_do_init (db.c:309)<br>
          ==501==    by 0x643CFF4: domain_db_init (domain.c:65)<br>
          ==501==    by 0x643E8C8: mod_init (domain_mod.c:232)<br>
          ==501==    by 0x4C8EF8: init_mod (sr_module.c:632)<br>
          ==501== <br>
          ==501== 328,352 (1,696 direct, 326,656 indirect) bytes in 2
          blocks are definitely lost in loss record 427 of 428<br>
          ==501==    at 0x4C2AB80: malloc (in
          /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)<br>
          ==501==    by 0x738EDC6: ??? (in
          /usr/lib/x86_64-linux-gnu/libsqlite3.so.0.8.6)<br>
          ==501==    by 0x7369569: ??? (in
          /usr/lib/x86_64-linux-gnu/libsqlite3.so.0.8.6)<br>
          ==501==    by 0x7371C47: ??? (in
          /usr/lib/x86_64-linux-gnu/libsqlite3.so.0.8.6)<br>
          ==501==    by 0x7371C6C: ??? (in
          /usr/lib/x86_64-linux-gnu/libsqlite3.so.0.8.6)<br>
          ==501==    by 0x73EF012: ??? (in
          /usr/lib/x86_64-linux-gnu/libsqlite3.so.0.8.6)<br>
          ==501==    by 0x7132D9A: db_sqlite_connect (my_con.c:62)<br>
          ==501==    by 0x7133314: db_sqlite_new_connection
          (my_con.c:134)<br>
          ==501==    by 0x5693A3: db_do_init (db.c:309)<br>
          ==501==    by 0x8577C0E: auth_fixup (authdb_mod.c:257)<br>
          ==501==    by 0x4A731B: fix_actions (route.c:459)<br>
          ==501==    by 0x4AA7EF: fix_expr (route.c:214)<br>
          ==501== <br>
          ==501== LEAK SUMMARY:<br>
          ==501==    definitely lost: 4,708 bytes in 8 blocks<br>
          ==501==    indirectly lost: 825,032 bytes in 6,077 blocks<br>
          ==501==      possibly lost: 328,824 bytes in 2,431 blocks<br>
          ==501==    still reachable: 4,259,419 bytes in 234 blocks<br>
          ==501==         suppressed: 0 bytes in 0 blocks<br>
          ==501== Reachable blocks (those to which a pointer was found)
          are not shown.<br>
          ==501== To see them, rerun with: --leak-check=full
          --show-leak-kinds=all<br>
          <br>
        </p>
        <p>Any hint will be very helpful!</p>
        <p>Best regards.<br>
        </p>
        <p><br>
        </p>
        <p><br>
        </p>
        <div id="Signature">
          <div name="divtagdefaultwrapper"
            style="font-family:Calibri,Arial,Helvetica,sans-serif;
            font-size:; margin:0">
            <div class="BodyFragment"><font size="2">
                <div class="PlainText">RODRIGO PIMENTA CARVALHO<br>
                  Inatel Competence Center<br>
                  Software<br>
                  Ph: +55 35 3471 9200 RAMAL 979<br>
                </div>
              </font></div>
          </div>
        </div>
        <br>
        <br>
        <div style="color: rgb(0, 0, 0);">
          <hr tabindex="-1" style="display:inline-block; width:98%">
          <div id="divRplyFwdMsg" dir="ltr"><font style="font-size:11pt"
              face="Calibri, sans-serif" color="#000000"><b>De:</b>
              <a class="moz-txt-link-abbreviated" href="mailto:users-bounces@lists.opensips.org">users-bounces@lists.opensips.org</a>
              <a class="moz-txt-link-rfc2396E" href="mailto:users-bounces@lists.opensips.org">&lt;users-bounces@lists.opensips.org&gt;</a> em nome de Liviu
              Chircu <a class="moz-txt-link-rfc2396E" href="mailto:liviu@opensips.org">&lt;liviu@opensips.org&gt;</a><br>
              <b>Enviado:</b> sexta-feira, 15 de abril de 2016 11:20<br>
              <b>Para:</b> <a class="moz-txt-link-abbreviated" href="mailto:users@lists.opensips.org">users@lists.opensips.org</a><br>
              <b>Assunto:</b> Re: [OpenSIPS-Users] How to avoid
              increasingly memory comsuption with AVPs?</font>
            <div> </div>
          </div>
          <div><tt>Hi Rodrigo,<br>
              <br>
              That's actually PKG memory, so you should fine tune the
              "-M" parameter according to your data and any instructions
              found in the SQLite module.<br>
              <br>
              As a side note, newer versions of OpenSIPS (2.2+) will
              properly indicate which type of memory you ran out of, so
              troubleshooting memory issues will become easier if you do
              the upgrade.<br>
            </tt>
            <pre class="moz-signature" cols="72">Liviu Chircu
OpenSIPS Developer
<a moz-do-not-send="true" id="LPlnk882142" class="moz-txt-link-freetext" href="http://www.opensips-solutions.com">http://www.opensips-solutions.com</a></pre>
            <div style="margin-bottom: 20px; overflow: auto; width:
              100%; text-indent: 0px;"
              id="LPBorder_GT_14607372330240.5782778834784025">
              <table style="width: 90%; background-color: rgb(255, 255,
                255); position: relative; overflow: auto; padding-top:
                20px; padding-bottom: 20px; margin-top: 20px;
                border-top: 1px dotted rgb(200, 200, 200);
                border-bottom: 1px dotted rgb(200, 200, 200);"
                id="LPContainer_14607372329950.4968402539681581"
                cellspacing="0">
                <tbody>
                  <tr style="border-spacing: 0px;" valign="top">
                    <td colspan="1" style="width: 250px; position:
                      relative; display: table-cell; padding-right:
                      20px;"
                      id="ImageCell_14607372329960.876831033910814">
                      <div style="background-color: rgb(255, 255, 255);
                        height: 38px; position: relative; margin: auto;
                        display: table; width: 116px;"
                        id="LPImageContainer_14607372329970.487860258824648">
                        <a moz-do-not-send="true" target="_blank"
                          href="http://www.opensips-solutions.com/"
                          style="display: table-cell; text-align:
                          center;"
                          id="LPImageAnchor_14607372329990.7877726253777939"><img
                            moz-do-not-send="true" aria-label="Imagem de
                            visualização com link selecionado. Toque
                            duas vezes para abrir o link."
                            style="display: inline-block; margin-left:
                            auto; margin-right: auto; max-width: 250px;
                            max-height: 250px; height: 38px; width:
                            116px; border-width: 0px; vertical-align:
                            bottom;"
                            src="http://www.opensips-solutions.com/imgs/opensips-solutions-logo.gif"
                            height="38" width="116"></a></div>
                    </td>
                    <td colspan="2" style="vertical-align: top;
                      position: relative; padding: 0px; display:
                      table-cell;"
                      id="TextCell_14607372330170.7617697637651935">
                      <div style="top: 0px; color: rgb(0, 120, 215);
                        font-weight: 400; font-size: 21px; font-family:
                        &quot;wf_segoe-ui_light&quot;,&quot;Segoe UI
                        Light&quot;,&quot;Segoe WP
                        Light&quot;,&quot;Segoe UI&quot;,&quot;Segoe
                        WP&quot;,Tahoma,Arial,sans-serif; line-height:
                        21px;"
                        id="LPTitle_14607372330170.8835583393811356">
                        <a moz-do-not-send="true" target="_blank"
                          href="http://www.opensips-solutions.com/"
                          style="text-decoration: none;"
                          id="LPUrlAnchor_14607372330200.7191777359545073">Home
                          — OpenSIPS Solutions</a></div>
                      <div style="margin: 10px 0px 16px; color: rgb(102,
                        102, 102); font-weight: 400; font-family:
                        &quot;wf_segoe-ui_normal&quot;,&quot;Segoe
                        UI&quot;,&quot;Segoe
                        WP&quot;,Tahoma,Arial,sans-serif; font-size:
                        14px; line-height: 14px;"
                        id="LPMetadata_14607372330210.39805319302236797">
                        <a class="moz-txt-link-abbreviated" href="http://www.opensips-solutions.com">www.opensips-solutions.com</a></div>
                      <div style="display: block; color: rgb(102, 102,
                        102); font-weight: 400; font-family:
                        &quot;wf_segoe-ui_normal&quot;,&quot;Segoe
                        UI&quot;,&quot;Segoe
                        WP&quot;,Tahoma,Arial,sans-serif; font-size:
                        14px; line-height: 20px; max-height: 100px;
                        overflow: hidden;"
                        id="LPDescription_14607372330220.7765623302230623">
                        OpenSIPS is a mature Open Source implementation
                        of a SIP server. OpenSIPS is more than a SIP
                        proxy/router as it includes application-level
                        functionalities.</div>
                    </td>
                  </tr>
                </tbody>
              </table>
            </div>
            <div class="moz-cite-prefix">On 15.04.2016 16:50, Rodrigo
              Pimenta Carvalho wrote:<br>
            </div>
            <blockquote type="cite">
              <div id="divtagdefaultwrapper" style="font-size:12pt;
                color:#000000; background-color:#FFFFFF;
                font-family:Calibri,Arial,Helvetica,sans-serif">
                <p><br>
                </p>
                <p>Hi.</p>
                <p><br>
                </p>
                <p>After a stress test with my OpenSIPS and few user
                  agent clients on-line, just sending SIP REGISTER
                  messages (1 at each minute), not making calls, I saw
                  this log:<br>
                </p>
                <p><br>
                </p>
                <p><br>
                </p>
                <p>Apr 15 10:09:20 [20441] WARNING:core:fm_malloc: Not
                  enough free memory, will attempt defragmentation<br>
                  Apr 15 10:09:20 [20441]
                  ERROR:db_sqlite:db_sqlite_allocate_rows: no memory
                  left<br>
                  Apr 15 10:09:20 [20441]
                  ERROR:db_sqlite:db_sqlite_convert_rows: no private
                  memory left<br>
                  Apr 15 10:09:20 [20441]
                  ERROR:db_sqlite:db_sqlite_convert_result: error while
                  converting rows<br>
                  Apr 15 10:09:20 [20441]
                  ERROR:db_sqlite:db_sqlite_store_result: error while
                  converting result<br>
                  Apr 15 10:09:20 [20441] ERROR:avpops:db_query_avp:
                  raw_query failed: db0(usr_preferences) select Value
                  from GeneralConfigurations ...</p>
                <p><br>
                </p>
                <p>So, I suspect that I have codified something wrong in
                  my opensips.cfg file.</p>
                <p>More precisely, I have used some AVPs and I'm note
                  sure if  such use is correct or if it is the cause of
                  increasingly memory consumption.</p>
                <p>For example, I have codified somethings like this:</p>
                <p><br>
                </p>
                <p><br>
                </p>
                <p>1        if($avp(I_A) == NULL){<br>
                                   avp_db_query("select Value from
                  GeneralConfigurations where Attribute =
                  'CONFIGURATION_INTERCOM_A_NAME'", "$avp(I_A)");<br>
                          }</p>
                <p><br>
                </p>
                <p>.</p>
                <p>.</p>
                <p>.</p>
                <p><br>
                </p>
                <p>2        if ($rU==$avp(M_TU)){<br>
                             $rU = $avp(M_T);<br>
                          }</p>
                <p>.</p>
                <p>.</p>
                <p>.</p>
                <p><br>
                </p>
                <p>3    if (nat_uac_test("34")) { <br>
                          if (is_method("REGISTER")) {<br>
                              fix_nated_register();<br>
                              setbflag(NAT);<br>
                              $avp(attr) = "in_another_network";<br>
                          } else {<br>
                              fix_nated_contact();<br>
                              setflag(NAT);<br>
                          }<br>
                      }</p>
                <p><br>
                </p>
                <p>.</p>
                <p>.</p>
                <p>.</p>
                <p>4                $avp(ContatoRegister) =
                  $(ct.fields(uri){s.select,0,;});<br>
                                    if($fn != NULL){<br>
                                       avp_db_query("UPDATE location SET
                  callerName='$fn'  where contact like
                  '$avp(ContatoRegister)%'");<br>
                                  }<br>
                                  $avp(ContatoRegister) = NULL;<br>
                </p>
                <p><br>
                </p>
                <p><br>
                </p>
                <p><br>
                </p>
                <p>Could some of the 4 piece of codes above causes some
                  increasingly memory consumption?</p>
                <p><br>
                </p>
                <p>Any hint will be very helpful!</p>
                <p><br>
                </p>
                <p>Best regards.<br>
                </p>
                <p><br>
                </p>
                <p><br>
                </p>
                <div id="Signature">
                  <div name="divtagdefaultwrapper"
                    style="font-family:Calibri,Arial,Helvetica,sans-serif;
                    font-size:; margin:0">
                    <div class="BodyFragment"><font size="2">
                        <div class="PlainText">RODRIGO PIMENTA CARVALHO<br>
                          Inatel Competence Center<br>
                          Software<br>
                          Ph: +55 35 3471 9200 RAMAL 979<br>
                        </div>
                      </font></div>
                  </div>
                </div>
              </div>
              <br>
              <fieldset class="mimeAttachmentHeader"></fieldset>
              <br>
              <pre>_______________________________________________
Users mailing list
<a moz-do-not-send="true" class="moz-txt-link-abbreviated" href="mailto:Users@lists.opensips.org">Users@lists.opensips.org</a>
<a moz-do-not-send="true" class="moz-txt-link-freetext" href="http://lists.opensips.org/cgi-bin/mailman/listinfo/users">http://lists.opensips.org/cgi-bin/mailman/listinfo/users</a>
</pre>
            </blockquote>
            <br>
          </div>
        </div>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
Users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Users@lists.opensips.org">Users@lists.opensips.org</a>
<a class="moz-txt-link-freetext" href="http://lists.opensips.org/cgi-bin/mailman/listinfo/users">http://lists.opensips.org/cgi-bin/mailman/listinfo/users</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>