summaryrefslogtreecommitdiffstats
path: root/src/utils
diff options
context:
space:
mode:
authorJan Doskočil <jan.doskocil@nic.cz>2024-07-23 15:51:35 +0200
committerDaniel Salzman <daniel.salzman@nic.cz>2024-07-23 20:02:39 +0200
commit60382484fb3029d640d04214789f38b9c9a1c39e (patch)
tree1f799372f0049aff4073c751731470977189d9ba /src/utils
parentlibknot: fix UBSAN warning 'applying zero offset to null pointer' (diff)
downloadknot-60382484fb3029d640d04214789f38b9c9a1c39e.tar.xz
knot-60382484fb3029d640d04214789f38b9c9a1c39e.zip
kxdpgun: fix memleak on unavailable slave XDP
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/kxdpgun/main.c42
1 files changed, 21 insertions, 21 deletions
diff --git a/src/utils/kxdpgun/main.c b/src/utils/kxdpgun/main.c
index 9d088e28d..91a657c14 100644
--- a/src/utils/kxdpgun/main.c
+++ b/src/utils/kxdpgun/main.c
@@ -476,7 +476,7 @@ static void quic_free_cb(knot_quic_reply_t *rpl)
void *xdp_gun_thread(void *_ctx)
{
xdp_gun_ctx_t *ctx = _ctx;
- struct knot_xdp_socket *xsk;
+ struct knot_xdp_socket *xsk = NULL;
struct timespec timer;
knot_xdp_msg_t pkts[ctx->at_once];
uint64_t errors = 0, lost = 0, duration = 0;
@@ -497,7 +497,7 @@ void *xdp_gun_thread(void *_ctx)
tcp_table = knot_tcp_table_new(ctx->qps, NULL);
if (tcp_table == NULL) {
ERR2("failed to allocate TCP connection table");
- return NULL;
+ goto cleanup;
}
}
if (ctx->quic) {
@@ -505,12 +505,12 @@ void *xdp_gun_thread(void *_ctx)
quic_creds = knot_creds_init_peer(NULL, NULL, 0);
if (quic_creds == NULL) {
ERR2("failed to initialize QUIC context");
- return NULL;
+ goto cleanup;
}
quic_table = knot_quic_table_new(ctx->qps * 100, SIZE_MAX, SIZE_MAX, 1232, quic_creds);
if (quic_table == NULL) {
ERR2("failed to allocate QUIC connection table");
- return NULL;
+ goto cleanup;
}
quic_table->qlog_dir = ctx->qlog_dir;
#else
@@ -531,8 +531,7 @@ void *xdp_gun_thread(void *_ctx)
if (ret != KNOT_EOK) {
ERR2("failed to initialize XDP socket#%u on interface %s (%s)",
ctx->thread_id, ctx->dev, knot_strerror(ret));
- knot_tcp_table_free(tcp_table);
- return NULL;
+ goto cleanup;
}
if (ctx->thread_id == 0) {
@@ -913,6 +912,22 @@ void *xdp_gun_thread(void *_ctx)
tick++;
}
+ char recv_str[40] = "", lost_str[40] = "", err_str[40] = "";
+ if (!(ctx->flags & KNOT_XDP_FILTER_DROP)) {
+ (void)snprintf(recv_str, sizeof(recv_str), ", received %"PRIu64, local_stats.ans_recv);
+ }
+ if (lost > 0) {
+ (void)snprintf(lost_str, sizeof(lost_str), ", lost %"PRIu64, lost);
+ }
+ if (errors > 0) {
+ (void)snprintf(err_str, sizeof(err_str), ", errors %"PRIu64, errors);
+ }
+ INFO2("thread#%02u: sent %"PRIu64"%s%s%s",
+ ctx->thread_id, local_stats.qry_sent, recv_str, lost_str, err_str);
+ local_stats.duration = ctx->duration;
+ collect_stats(&global_stats, &local_stats);
+
+cleanup:
knot_xdp_deinit(xsk);
if (ctx->tcp) {
@@ -933,21 +948,6 @@ void *xdp_gun_thread(void *_ctx)
knot_creds_free(quic_creds);
#endif // ENABLE_QUIC
- char recv_str[40] = "", lost_str[40] = "", err_str[40] = "";
- if (!(ctx->flags & KNOT_XDP_FILTER_DROP)) {
- (void)snprintf(recv_str, sizeof(recv_str), ", received %"PRIu64, local_stats.ans_recv);
- }
- if (lost > 0) {
- (void)snprintf(lost_str, sizeof(lost_str), ", lost %"PRIu64, lost);
- }
- if (errors > 0) {
- (void)snprintf(err_str, sizeof(err_str), ", errors %"PRIu64, errors);
- }
- INFO2("thread#%02u: sent %"PRIu64"%s%s%s",
- ctx->thread_id, local_stats.qry_sent, recv_str, lost_str, err_str);
- local_stats.duration = ctx->duration;
- collect_stats(&global_stats, &local_stats);
-
return NULL;
}