Fix memleak: if we bail out, we need to free the json as we promised we would.