From 0cfe5606e8555c2c9efe2fbf8b21109214eaa39f Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Sat, 12 Apr 2014 11:04:34 +1000 Subject: [PATCH] Http requests will always be small so use the stack array only --- src/libckpool.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/libckpool.c b/src/libckpool.c index e2bb99c4..265656ea 100644 --- a/src/libckpool.c +++ b/src/libckpool.c @@ -496,9 +496,9 @@ void empty_socket(int fd) json_t *json_rpc_call(connsock_t *cs, const char *rpc_req) { + char http_req[PAGESIZE]; json_error_t err_val; json_t *val = NULL; - char *http_req = NULL, base_req[PAGESIZE]; int len, ret; if (unlikely(cs->fd < 0)) { @@ -526,15 +526,13 @@ json_t *json_rpc_call(connsock_t *cs, const char *rpc_req) LOGWARNING("Zero length rpc_req passed to json_rpc_call"); goto out; } - snprintf(base_req, PAGESIZE, + snprintf(http_req, PAGESIZE, "POST / HTTP/1.1\n" "Authorization: Basic %s\n" "Host: %s:%s\n" "Content-type: application/json\n" - "Content-Length: %d\n\n", - cs->auth, cs->url, cs->port, len); - http_req = strdup(base_req); - realloc_strcat(&http_req, rpc_req); + "Content-Length: %d\n\n%s", + cs->auth, cs->url, cs->port, len, rpc_req); len = strlen(http_req); ret = write_socket(cs->fd, http_req, len); @@ -567,7 +565,6 @@ json_t *json_rpc_call(connsock_t *cs, const char *rpc_req) LOGWARNING("JSON decode failed(%d): %s", err_val.line, err_val.text); out: dealloc(&cs->buf); - free(http_req); return val; }