0

This is a stack trace of calling json_string() :

  1. json_string(const char *value)

  2. json_stringn(value, strlen(value))

  3. json_stringn_nocheck(value, len)

  4. string_create(value, len, 0)

string_create then call json_strndup(value,len) to duplicate value of string.

The problem is there that I couldn't find out when this allocated memory for value is freed.

H.Tibat
  • 353
  • 2
  • 9
  • 1
    You should look for reference counting in the jansson documentation. `json_decref` is your friend. – Gerhardh Jul 17 '18 at 08:55
  • Your right. Also I had used `json_array_append_new` to add a string to an array. Dose `json_array_append_new` decrease reference of it value? – H.Tibat Jul 17 '18 at 09:27
  • Its look `json_array_append_new` doesn't decrease the reference count, and do `reference stealing`. – H.Tibat Jul 17 '18 at 09:31
  • Yes, it "steals" the reference. But otherwise it would **in**crease the reference. – Gerhardh Jul 17 '18 at 10:21
  • If you don't want the reference stealing, use the version without suffix `_new`. – Gerhardh Jul 17 '18 at 10:26
  • "However, some functions steal the reference, i.e. they have the same result as if the user called json_decref() on the argument right after calling the function." https://jansson.readthedocs.io/en/2.10/apiref.html#reference-count – H.Tibat Jul 21 '18 at 07:06

0 Answers0