src/{query,json}.c: fix malloc size calculations