patched cJSON (to be committed back to the author) to make it thread safe and fixed two forgotten catches of malloc failures (also to be committed back to the author)