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

This commit is contained in:
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

@ -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;
}