cjdelisle/cjdns — pull request #151 by eblanton (2012-12-04 02:05:27+00:00)
Title: Change the JSON de-serialization parseString to use heap allocation

This changeset causes the JSON de-serialization to use a doubling heap allocation (starting with 256 bytes, doubling up to 1MB as necessary) to parse strings. The old code uses a 1MB buffer on the stack which, if parseString is inlined, rapidly causes the stack to blow. (It is inlined on my OS X Snow Leopard machine).

I am not completely confident that my allocator usage is kosher. If it isn't, let me know and I'll find another solution.

Simply changing the buffer size from 1<<20 to 1<<16 fixes this problem for me; however, that is a data-dependent fix. This fix should be more robust.