fix(lnm): some small bugs
ci/woodpecker/push/build Pipeline was successful Details

lnm
Jef Roosens 2023-12-05 20:21:28 +01:00
parent 8ae59f1031
commit 876e5a7de4
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
2 changed files with 12 additions and 6 deletions

View File

@ -275,9 +275,10 @@ void lnm_http_loop_process_finish(lnm_http_conn *conn) {
return;
}
lnm_http_loop_ctx_reset(conn->ctx);
lnm_http_loop_ctx *ctx = conn->ctx;
lnm_http_loop_ctx_reset(ctx);
conn->state = lnm_loop_state_req;
ctx->state = lnm_http_loop_state_parse_req;
}
void (*process_fns[])(lnm_http_conn *conn) = {

View File

@ -3,6 +3,7 @@
#include <poll.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include "lnm/common.h"
#include "lnm/loop_internal.h"
@ -43,10 +44,9 @@ lnm_err lnm_loop_accept(lnm_loop *l) {
// Append connection to list of connections
if ((size_t)conn_fd >= l->conns.len) {
lnm_loop_conn **new =
l->conns.len == 0
? calloc(sizeof(lnm_loop_conn *), conn_fd + 1)
: realloc(l->conns.arr, sizeof(lnm_loop_conn *) * (conn_fd + 1));
// We always calloc as a realloc might introduce unitialized values in the
// array
lnm_loop_conn **new = calloc(sizeof(lnm_loop_conn *), conn_fd + 1);
if (new == NULL) {
close(conn_fd);
@ -54,6 +54,11 @@ lnm_err lnm_loop_accept(lnm_loop *l) {
return lnm_err_failed_alloc;
}
if (l->conns.len > 0) {
memcpy(new, l->conns.arr, l->conns.len * sizeof(lnm_loop_conn *));
free(l->conns.arr);
}
l->conns.arr = new;
l->conns.len = conn_fd + 1;
}