Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/improve memory management #9

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
.PHONY: test test_e2e

test:
docker-compose build test && docker-compose run --rm test
docker-compose down -t 0
docker compose build test && docker compose run --rm test
docker compose down -t 0

test_e2e:
docker-compose build test_e2e && docker-compose run --rm test_e2e
docker-compose down -t 0
docker compose build test_e2e && docker compose run --rm test_e2e
docker compose down -t 0
2 changes: 1 addition & 1 deletion docker/Dockerfile.e2e
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM rust:1.63.0-alpine3.16

USER root

RUN apk add --no-cache musl-dev openssl-dev pkgconfig && cargo install websocat
RUN apk add --no-cache musl-dev openssl-dev pkgconfig && cargo install websocat@1.10.0

COPY ./docker/test_e2e.sh /usr/local/bin/test_e2e
RUN chmod +x /usr/local/bin/test_e2e
Expand Down
4 changes: 2 additions & 2 deletions docker/Dockerfile.nginx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM k8s.gcr.io/ingress-nginx/controller:v0.44.0 as builder
FROM k8s.gcr.io/ingress-nginx/controller:v1.1.1 as builder

USER root

Expand All @@ -14,5 +14,5 @@ RUN cd ./nginx && \
--add-dynamic-module=../ngx_http_websocket_stat_module && \
make modules

FROM k8s.gcr.io/ingress-nginx/controller:v0.44.0
FROM k8s.gcr.io/ingress-nginx/controller:v1.1.1
COPY --from=builder /tmp/nginx/objs/ngx_http_websocket_stat_module.so /etc/nginx/modules/
6 changes: 3 additions & 3 deletions src/ngx_http_websocket_stat_format.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ compare_occurance(const void *_first, const void *_second)
ngx_array_t *
ngx_array_create(void *pool, size_t size, size_t el_size)
{
ngx_array_t *res = malloc(sizeof(ngx_array_t));
ngx_array_t *res = ngx_palloc(pool, sizeof(ngx_array_t));
res->nelts = 0;
res->elts = malloc(100 * el_size);
res->elts = ngx_palloc(pool, 100 * el_size);
res->el_size = el_size;
return res;
}
Expand Down Expand Up @@ -191,7 +191,7 @@ char *
apply_template(compiled_template *template_cmpl, ngx_http_request_t *r,
void *data)
{
char *result = malloc(strlen(template_cmpl->compiled_template_str) + 1);
char *result = ngx_palloc(template_cmpl->pool, strlen(template_cmpl->compiled_template_str) + 1);
strcpy(result, template_cmpl->compiled_template_str);
unsigned int i;
char buff[256];
Expand Down
2 changes: 1 addition & 1 deletion src/ngx_http_websocket_stat_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ ws_do_log(compiled_template *template, ngx_http_request_t *r, void *ctx)
if (!log_line) return;
ngx_write_fd(srvcf->ws_log->file->fd, log_line, strlen(log_line));
ngx_write_fd(srvcf->ws_log->file->fd, &CARET_RETURN, sizeof(char));
free(log_line);
ngx_pfree(template->pool, log_line);
}

static int
Expand Down