Memory is corrupted by json-cpp 0.5.0 in following configuration:
I used MSVC 2008.
# define JSON_VALUE_USE_INTERNAL_MAP 1
// # define JSON_USE_SIMPLE_INTERNAL_ALLOCATOR 1
JSON_VALUE_USE_INTERNAL_MAP is necessary for me to make getMemberNames() return names sorted as in json data (see bug ID: 3014601)
Defining JSON_USE_SIMPLE_INTERNAL_ALLOCATOR to 1 removes problem.
Way to reproduce:
I took json data with simple structure, but long text valus (whole json size: 30K).
I parsed that json in a loop.
After parsing 130-150 times program crashes during occasional CRT heap check.
Here is a code that will crash in 2 seconds (less than 150 iterations of loop) (MSVC2008):
const std::string sJason = "{\"x\":{\"d\":{\"t\":\"v\"},\"t1\":[\"v1\"],\"t2\":[\"a\",\"b\",\"c\"]}}";
int cnt = 0;
while(true)
{
cnt++;
Json::Value root; // will contains the root value after parsing.
Json::Reader reader;
const bool parsingSuccessful = reader.parse(sJason, root);
printf("try %d done!\n", cnt);
}
NOTE! don't forget about mode in config.h:
# define JSON_VALUE_USE_INTERNAL_MAP 1
//# define JSON_USE_SIMPLE_INTERNAL_ALLOCATOR 1
P.S. The more internal arrays or objects we have in above sample, the less loop iterations are necessary to crash.
I do not have time to study this isue. I suspect that there are many other issues with this container as it has no unit tests (at least we can now write some). This is the reason it is marked has experimental.
Dropped from codebase. We might allow hashmap via configuration in the future.