<div dir="ltr">Ok, this was absolutely useless - $TV(Sn) gives ms ;)</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Feb 11, 2013 at 8:59 AM, Mino Haluz <span dir="ltr">&lt;<a href="mailto:mino.haluz@gmail.com" target="_blank">mino.haluz@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I cannot free it after calling pv_get_strval, because it seems that this value is not used instantly after calling :/ So it should be freed somewhere else and I do not know where.</div>
<div class="HOEnZb"><div class="h5"><div class="gmail_extra">
<br><br><div class="gmail_quote">On Mon, Feb 11, 2013 at 8:33 AM, Mino Haluz <span dir="ltr">&lt;<a href="mailto:mino.haluz@gmail.com" target="_blank">mino.haluz@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div dir="ltr">Thanks, yes, I already solved it like this:<div><br></div><div><div><div>int pv_get_timenows2(struct sip_msg *msg, pv_param_t *param,</div><div>                pv_value_t *res)</div><div>{</div></div>
<div>        //time_t t;</div><div>
<div>        struct timeval tv;</div><div>        char buf[30];</div><div>        str _s;</div><div>        gettimeofday(&amp;tv, NULL);</div><div>        unsigned long long msEpoch =</div><div>                (unsigned long long)(tv.tv_sec) * 1000 +</div>


<div>                (unsigned long long)(tv.tv_usec) / 1000;</div><div>        _s.len = sprintf(buf, &quot;%lld&quot;, msEpoch);</div></div><div>        _s.s = (char *)malloc(_s.len+1);</div><div>        strcpy(_s.s, buf);</div>

<div>
<div>        return pv_get_strval(msg, param, res, &amp;_s);</div><div>}</div></div></div><div><br></div><div>I know that it is rather C related question, but I would like to avoid some memory leaks in kamailio. </div><div>


<br></div><div>pv_get_strval seems to be some builtin kamailio function, so the question is, does it free _s.s automatically ?</div><span><font color="#888888"><div><br></div><div>Mino</div></font></span></div>
<div><div><div class="gmail_extra"><br><br><div class="gmail_quote">
On Fri, Feb 8, 2013 at 10:14 PM, Daniel-Constantin Mierla <span dir="ltr">&lt;<a href="mailto:miconda@gmail.com" target="_blank">miconda@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">



  
    
  
  <div bgcolor="#FFFFFF" text="#000000">
    The problem is that buf is allocated on the stack, on a zone
    reserved for pv_get_timenows2() function, which is destroyed as soon
    as the function execution ends.<br>
    <br>
    You either define buf as static, or you allocate it dynamically in
    the function and free it later.<br>
    <br>
    Cheers,<br>
    Daniel<div><div><br>
    <br>
    <div>On 2/7/13 7:25 PM, Mino Haluz wrote:<br>
    </div>
    </div></div><blockquote type="cite"><div><div>
      <div dir="ltr">I added new pseudovariale $TMS which gives time in
        miliseconds. If I print $TMS value it is ok, but when I assign
        it to avp, it gives strange values.
        <div><br>
        </div>
        <div>pv_time.c</div>
        <div><br>
        </div>
        <div>
          <div>int pv_get_timenows2(struct sip_msg *msg, pv_param_t
            *param,</div>
          <div>                pv_value_t *res)</div>
          <div>{</div>
          <div>        struct timeval tv;<br>
          </div>
          <div>        char buf[30];</div>
          <div>        str _s;</div>
          <div>        gettimeofday(&amp;tv, NULL);</div>
          <div>        unsigned long long msEpoch =</div>
          <div>                (unsigned long long)(tv.tv_sec) * 1000 +</div>
          <div>                (unsigned long long)(tv.tv_usec) / 1000;</div>
          <div>        _s.len = sprintf(buf, &quot;%lld&quot;, msEpoch);</div>
          <div>        _s.s = buf;   //&lt;------- I think problem is
            here<br>
          </div>
          <div>        return pv_get_strval(msg, param, res, &amp;_s);</div>
          <div>}</div>
        </div>
        <div><br>
        </div>
        <div>So how should I properly copy buf to _s ? </div>
        <div><br>
        </div>
        <div>Thanks,</div>
        <div>Mino</div>
        <div><br>
        </div>
        <div><br>
        </div>
        <div><br>
        </div>
      </div>
      <div class="gmail_extra"><br>
        <br>
        <div class="gmail_quote">On Thu, Feb 7, 2013 at 11:00 AM, Mino
          Haluz <span dir="ltr">&lt;<a href="mailto:mino.haluz@gmail.com" target="_blank">mino.haluz@gmail.com</a>&gt;</span>
          wrote:<br>
          <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
            <div dir="ltr">Hi,
              <div><br>
              </div>
              <div>I assume there is no avp or function which could give
                me duration of ended dialog in miliseconds (I have to
                send it in RADIUS message). I can run some bash script
                which could return me this value but seems to me bit
                awkward.</div>
              <div><br>
              </div>
              <div>How you would do it? To adjust dialog module so that
                it could return it to some avp value within dialog-end
                event route and thus save it to radius?</div>
              <span><font color="#888888">
                  <div>
                    <br>
                  </div>
                  <div>Mino</div>
                </font></span></div>
          </blockquote>
        </div>
        <br>
      </div>
      <br>
      <fieldset></fieldset>
      <br>
      </div></div><pre>_______________________________________________
sr-dev mailing list
<a href="mailto:sr-dev@lists.sip-router.org" target="_blank">sr-dev@lists.sip-router.org</a>
<a href="http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev" target="_blank">http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev</a><span><font color="#888888">
</font></span></pre><span><font color="#888888">
    </font></span></blockquote><span><font color="#888888">
    <br>
    <pre cols="72">-- 
Daniel-Constantin Mierla - <a href="http://www.asipto.com" target="_blank">http://www.asipto.com</a>
<a href="http://twitter.com/#!/miconda" target="_blank">http://twitter.com/#!/miconda</a> - <a href="http://www.linkedin.com/in/miconda" target="_blank">http://www.linkedin.com/in/miconda</a>
Kamailio World Conference, April 16-17, 2013, Berlin
 - <a href="http://conference.kamailio.com" target="_blank">http://conference.kamailio.com</a> -</pre>
  </font></span></div>

<br>_______________________________________________<br>
sr-dev mailing list<br>
<a href="mailto:sr-dev@lists.sip-router.org" target="_blank">sr-dev@lists.sip-router.org</a><br>
<a href="http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev" target="_blank">http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev</a><br>
<br></blockquote></div><br></div>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>