<html>
  <head>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    OK, I pushed it to branches 4.2 and 4.1<br>
    <br>
    Cheers,<br>
    Daniel<br>
    <br>
    <div class="moz-cite-prefix">On 06/11/14 11:15, dongwf wrote:<br>
    </div>
    <blockquote
      cite="mid:36ff379b.234fe.149849a2eee.Coremail.dongwflj@163.com"
      type="cite">
      <div
        style="line-height:1.7;color:#000000;font-size:14px;font-family:Arial">Hi,
        I checked with my test env, your fix is ok, please port, thanks!<br>
        <br>
        <br>
        <br>
        <br>
        <br>
        At 2014-11-05 21:35:40, "Daniel-Constantin Mierla"
        <a class="moz-txt-link-rfc2396E" href="mailto:miconda@gmail.com"><miconda@gmail.com></a> wrote:<br>
        <blockquote id="isReplyContent" style="PADDING-LEFT: 1ex;
          MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">
          Hello,<br>
          <br>
          I pushed a fix that should release the json object:<br>
          <br>
          -
          <a moz-do-not-send="true" class="moz-txt-link-freetext"
href="http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=def8d2600422a442b971c204df98594b0dfdaacd">http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=def8d2600422a442b971c204df98594b0dfdaacd</a><br>
          <br>
          <pre wrap="">dst_pv->setf() should copy (clone) of the string value and then the object can be unreferenced.</pre>
          <br>
          If works ok, then I will backport -- I didn't have any server
          with json library at hand to give it a minimum test.<br>
          <br>
          Cheers,<br>
          Daniel<br>
          <br>
          <div class="moz-cite-prefix">On 05/11/14 11:23, dongwf wrote:<br>
          </div>
          <blockquote
            cite="mid:2ecd9401.be12.1497f7b1bb3.Coremail.dongwflj@163.com"
            type="cite">
            <div
              style="line-height:1.7;color:#000000;font-size:14px;font-family:Arial"><span
                style="line-height: 23.7999992370605px;">One more
                question based the last mail, if I want to return the j
                object pointer via PV to script( created as </span><span
                style="line-height: 23.7999992370605px;">struct
                json_object *j = json_tokener_parse(json_s.s);</span><span
                style="line-height: 23.7999992370605px;">), how can I
                achieve that? Then I can put the pointer back to another
                exported api and release the pointer via
                json_object_put, thanks!</span><br>
              <br>
              <br>
              <br>
              <br>
              <br>
              At 2014-11-05 17:54:46, "dongwf" <a
                moz-do-not-send="true" class="moz-txt-link-rfc2396E"
                href="mailto:dongwflj@163.com"><dongwflj@163.com></a>
              wrote:<br>
              <blockquote id="isReplyContent" style="PADDING-LEFT: 1ex;
                MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">
                <div
                  style="line-height:1.7;color:#000000;font-size:14px;font-family:Arial">
                  <div>Hi:</div>
                  <div>I am trying to use json module in script
                    with json_get_field exported api, I found in it's
                    implementation, the api will call struct json_object
                    *j = json_tokener_parse(json_s.s); but didn't call
                    json_object_put for this j object, then the object
                    will leak. So my question is how to release the new
                    j object? We can't release in json_get_field(), that
                    will cause the returned string become to rubbish,
                    thanks!</div>
                  <div>Below is the api's code in
                    module\json\json_funcs.c:</div>
                  <div>
                    <div>int json_get_field(struct sip_msg* msg, char*
                      json, char* field, char* dst)</div>
                    <div>{</div>
                    <div>  str json_s;</div>
                    <div>  str field_s;</div>
                    <div>  pv_spec_t *dst_pv;</div>
                    <div>  pv_value_t dst_val;</div>
                    <div><br>
                    </div>
                    <div><span class="Apple-tab-span"
                        style="white-space:pre"> </span>if
                      (fixup_get_svalue(msg, (gparam_p)json,
                      &json_s) != 0) {</div>
                    <div><span class="Apple-tab-span"
                        style="white-space:pre"> </span>LM_ERR("cannot
                      get json string value\n");</div>
                    <div><span class="Apple-tab-span"
                        style="white-space:pre"> </span>return -1;</div>
                    <div><span class="Apple-tab-span"
                        style="white-space:pre"> </span>}</div>
                    <div><br>
                    </div>
                    <div><span class="Apple-tab-span"
                        style="white-space:pre"> </span>if
                      (fixup_get_svalue(msg, (gparam_p)field,
                      &field_s) != 0) {</div>
                    <div><span class="Apple-tab-span"
                        style="white-space:pre"> </span>LM_ERR("cannot
                      get field string value\n");</div>
                    <div><span class="Apple-tab-span"
                        style="white-space:pre"> </span>return -1;</div>
                    <div><span class="Apple-tab-span"
                        style="white-space:pre"> </span>}</div>
                    <div><span class="Apple-tab-span"
                        style="white-space:pre"> </span></div>
                    <div><span class="Apple-tab-span"
                        style="white-space:pre"> </span>dst_pv =
                      (pv_spec_t *)dst;</div>
                    <div><span class="Apple-tab-span"
                        style="white-space:pre"> </span></div>
                    <div><span class="Apple-tab-span"
                        style="white-space:pre"> </span>struct
                      json_object *j = json_tokener_parse(json_s.s);</div>
                    <div><br>
                    </div>
                    <div><span class="Apple-tab-span"
                        style="white-space:pre"> </span>if
                      (is_error(j)) {</div>
                    <div><span class="Apple-tab-span"
                        style="white-space:pre"> </span>LM_ERR("empty
                      or invalid JSON\n");</div>
                    <div><span class="Apple-tab-span"
                        style="white-space:pre"> </span>return -1;</div>
                    <div><span class="Apple-tab-span"
                        style="white-space:pre"> </span>}</div>
                    <div><br>
                    </div>
                    <div><span class="Apple-tab-span"
                        style="white-space:pre"> </span>char *value =
                      (char*)json_object_to_json_string(json_object_object_get(j,
                      field_s.s));</div>
                    <div><br>
                    </div>
                    <div><span class="Apple-tab-span"
                        style="white-space:pre"> </span>dst_val.rs.s =
                      value;</div>
                    <div><span class="Apple-tab-span"
                        style="white-space:pre"> </span>dst_val.rs.len
                      = strlen(value);</div>
                    <div><span class="Apple-tab-span"
                        style="white-space:pre"> </span>dst_val.flags =
                      PV_VAL_STR;</div>
                    <div><span class="Apple-tab-span"
                        style="white-space:pre"> </span>dst_pv->setf(msg,
                      &dst_pv->pvp, (int)EQ_T, &dst_val);</div>
                    <div><br>
                    </div>
                    <div><span class="Apple-tab-span"
                        style="white-space:pre"> </span>return 1;</div>
                    <div>}</div>
                  </div>
                  <br>
                  <blockquote id="isReplyContent" style="PADDING-LEFT:
                    1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc
                    1px solid"><br>
                  </blockquote>
                </div>
                <br>
                <br>
                <span title="neteasefooter"><span
                    id="netease_mail_footer"></span></span></blockquote>
            </div>
            <br>
            <br>
            <span title="neteasefooter"><span id="netease_mail_footer"></span></span><br>
            <fieldset class="mimeAttachmentHeader"></fieldset>
            <br>
            <pre wrap="">_______________________________________________
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list
<a moz-do-not-send="true" class="moz-txt-link-abbreviated" href="mailto:sr-users@lists.sip-router.org">sr-users@lists.sip-router.org</a>
<a moz-do-not-send="true" class="moz-txt-link-freetext" href="http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users">http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users</a>
</pre>
          </blockquote>
          <br>
          <pre class="moz-signature" cols="72">-- 
Daniel-Constantin Mierla
<a moz-do-not-send="true" class="moz-txt-link-freetext" href="http://twitter.com/#%21/miconda">http://twitter.com/#!/miconda</a> - <a moz-do-not-send="true" class="moz-txt-link-freetext" href="http://www.linkedin.com/in/miconda">http://www.linkedin.com/in/miconda</a>
Kamailio Advanced Training, Nov 24-27, Berlin - <a moz-do-not-send="true" class="moz-txt-link-freetext" href="http://www.asipto.com">http://www.asipto.com</a></pre>
        </blockquote>
      </div>
      <br>
      <br>
      <span title="neteasefooter"><span id="netease_mail_footer"></span></span>
    </blockquote>
    <br>
    <pre class="moz-signature" cols="72">-- 
Daniel-Constantin Mierla
<a class="moz-txt-link-freetext" href="http://twitter.com/#!/miconda">http://twitter.com/#!/miconda</a> - <a class="moz-txt-link-freetext" href="http://www.linkedin.com/in/miconda">http://www.linkedin.com/in/miconda</a>
Kamailio Advanced Training, Nov 24-27, Berlin - <a class="moz-txt-link-freetext" href="http://www.asipto.com">http://www.asipto.com</a></pre>
  </body>
</html>