json_string vs json_char *

ganesh
2012-11-08
2013-06-12
  • ganesh
    ganesh
    2012-11-08

    Hi, I have the following boost unit test:
    BOOST_AUTO_TEST_CASE(check_string)
    {
         JSONNode node;
         json_string sResult = json_write_formatted(&node);    
          json_free(&sResult);
    }
    Memory leak is detected if I use the above unit test.
    1>  Detected memory leaks!
    1>  Dumping objects ->
    1>  {794} normal block at 0x00772420, 12 bytes long.
    1>   Data: <{ }         > 7B 00 7D 00 00 00 CD CD CD CD CD CD


    But if I use json_char*, there is no memory leak:
    BOOST_AUTO_TEST_CASE(check_char)
    {
         JSONNode node;
          json_char *jc =  json_write_formatted(&node);
          json_free(jc);
    }

    How to use json_string without memory leak ?

    Thanks !

     
  • That is up to your string libraries implementation.  json_string is defined as std::string in almost all cases, you are getting a false positive.  It's possible that a global is being initialized too, which also causes false positives.