Ensure all memory is free'd in case of exceptions in alloc_query_params()