kore

Kore is a web application platform for writing scalable, concurrent web based processes in C or Python.
Commits | Files | Refs | README | LICENSE | git clone https://git.kore.io/kore.git

commit 4fd6d8a7a48421f3ca16eda65c7940be64448082
parent 7bdae240cfa0f34116416b7c01f469425e2a9ea5
Author: Joris Vink <joris@coders.se>
Date:   Sun, 29 Nov 2015 17:22:30 +0100

Correct usage of http_request_header().

Since latest change we no longer need free its result.

Diffstat:
src/auth.c | 10++--------
src/http.c | 24+++++-------------------
src/websocket.c | 6------
3 files changed, 7 insertions(+), 33 deletions(-)

diff --git a/src/auth.c b/src/auth.c @@ -123,20 +123,14 @@ kore_auth_cookie(struct http_request *req, struct kore_auth *auth) break; } - if (i == v) { - kore_mem_free(cookie); + if (i == v) return (KORE_RESULT_ERROR); - } c = cookies[i]; - if ((value = strchr(c, '=')) == NULL) { - kore_mem_free(cookie); + if ((value = strchr(c, '=')) == NULL) return (KORE_RESULT_ERROR); - } i = kore_validator_check(req, auth->validator, ++value); - kore_mem_free(cookie); - return (i); } diff --git a/src/http.c b/src/http.c @@ -170,7 +170,7 @@ http_request_new(struct connection *c, const char *host, TAILQ_INIT(&(req->files)); if (!http_request_header(req, "user-agent", &(req->agent))) - req->agent = kore_strdup("unknown"); + req->agent = "unknown"; #if defined(KORE_USE_TASKS) LIST_INIT(&(req->tasks)); @@ -429,8 +429,6 @@ http_request_free(struct http_request *req) if (req->multipart_body != NULL) kore_mem_free(req->multipart_body); - if (req->agent != NULL) - kore_mem_free(req->agent); if (req->hdlr_extra != NULL && !(req->flags & HTTP_REQUEST_RETAIN_EXTRA)) kore_mem_free(req->hdlr_extra); @@ -592,7 +590,7 @@ http_header_recv(struct netbuf *nb) if (req->agent == NULL && !strcasecmp(hdr->header, "user-agent")) - req->agent = kore_strdup(hdr->value); + req->agent = hdr->value; } if (req->flags & HTTP_REQUEST_EXPECT_BODY) { @@ -606,14 +604,11 @@ http_header_recv(struct netbuf *nb) clen = kore_strtonum(p, 10, 0, LONG_MAX, &v); if (v == KORE_RESULT_ERROR) { kore_debug("content-length invalid: %s", p); - kore_mem_free(p); req->flags |= HTTP_REQUEST_DELETE; http_error_response(req->owner, 411); return (KORE_RESULT_OK); } - kore_mem_free(p); - if (clen == 0) { req->flags |= HTTP_REQUEST_COMPLETE; req->flags &= ~HTTP_REQUEST_EXPECT_BODY; @@ -827,32 +822,24 @@ http_populate_multipart_form(struct http_request *req, int *v) return (KORE_RESULT_ERROR); h = kore_split_string(type, ";", args, 3); - if (h != 2) { - kore_mem_free(type); + if (h != 2) return (KORE_RESULT_ERROR); - } - if (strcasecmp(args[0], "multipart/form-data")) { - kore_mem_free(type); + if (strcasecmp(args[0], "multipart/form-data")) return (KORE_RESULT_ERROR); - } - if ((val = strchr(args[1], '=')) == NULL) { - kore_mem_free(type); + if ((val = strchr(args[1], '=')) == NULL) return (KORE_RESULT_ERROR); - } val++; slen = strlen(val); boundary = kore_malloc(slen + 3); if (!kore_snprintf(boundary, slen + 3, &l, "--%s", val)) { kore_mem_free(boundary); - kore_mem_free(type); return (KORE_RESULT_ERROR); } slen = l; - kore_mem_free(type); req->multipart_body = http_body_bytes(req, &blen); if (slen < 3 || blen < (slen * 2)) { @@ -1152,7 +1139,6 @@ http_response_normal(struct http_request *req, struct connection *c, if ((*conn == 'c' || *conn == 'C') && !strcasecmp(conn, "close")) connection_close = 1; - kore_mem_free(conn); } } diff --git a/src/websocket.c b/src/websocket.c @@ -59,25 +59,19 @@ kore_websocket_handshake(struct http_request *req, struct kore_wscbs *wscbs) } if (!http_request_header(req, "sec-websocket-version", &version)) { - kore_mem_free(key); http_response_header(req, "sec-websocket-version", "13"); http_response(req, HTTP_STATUS_BAD_REQUEST, NULL, 0); return; } if (strcmp(version, "13")) { - kore_mem_free(key); - kore_mem_free(version); http_response_header(req, "sec-websocket-version", "13"); http_response(req, HTTP_STATUS_BAD_REQUEST, NULL, 0); return; } - kore_mem_free(version); - buf = kore_buf_create(128); kore_buf_appendf(buf, "%s%s", key, WEBSOCKET_SERVER_RESPONSE); - kore_mem_free(key); (void)SHA1_Init(&sctx); (void)SHA1_Update(&sctx, buf->data, buf->offset);