Fix for broken json task

Hello, I believe I have a fix for this patch. 
The changes I have made are listed on this diff output : 
http://pastebin.com/J1Zyy2kZ

Also the code I used to test it is here : 
https://dl.dropboxusercontent.com/u/23851310/test.cpp

I checked for memory leaks using valgrind and while with the original code there was some, in my version there are no leaks. 

I hope everything works out! I will be available for contact on the irc channel!