1
0
mirror of https://github.com/rtbrick/bngblaster.git synced 2024-05-06 15:54:57 +00:00

fix valgrind socket leak and invalid write errors

This commit is contained in:
Hannes Gredler
2022-04-19 20:59:03 +00:00
parent 45c6ef132f
commit c4ef0d0eb8
2 changed files with 16 additions and 3 deletions

View File

@@ -202,7 +202,10 @@ lspgen_ctrl_close_cb(timer_s *timer)
/*
* Close the connection.
*/
close(ctx->ctrl_socket_sockfd);
if (ctx->ctrl_socket_sockfd > 0) {
close(ctx->ctrl_socket_sockfd);
ctx->ctrl_socket_sockfd = 0;
}
LOG(NORMAL, "Closing connection to %s\n", ctx->ctrl_socket_path);
}
@@ -318,6 +321,9 @@ lspgen_ctrl_connect_cb(timer_s *timer)
memset(&addr, 0, sizeof(addr));
addr.sun_family = AF_UNIX;
strncpy(addr.sun_path, ctx->ctrl_socket_path, sizeof(addr.sun_path)-1);
if (ctx->ctrl_socket_sockfd != 0) {
LOG(CTRL, "CTRL socket to %s still unfreed\n", ctx->ctrl_socket_path);
}
ctx->ctrl_socket_sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
res = connect(ctx->ctrl_socket_sockfd, (struct sockaddr *)&addr, SUN_LEN(&addr));
@@ -352,5 +358,7 @@ lspgen_ctrl_connect_cb(timer_s *timer)
return;
}
close(ctx->ctrl_socket_sockfd);
ctx->ctrl_socket_sockfd = 0;
LOG(ERROR, "Error connecting to %s, %s\n", ctx->ctrl_socket_path, strerror(errno));
}

View File

@@ -814,13 +814,13 @@ void
lsdb_delete_ctx(struct lsdb_ctx_ *ctx)
{
timer_flush_root(&ctx->timer_root);
dict_free(ctx->link_dict, lsdb_free_link);
ctx->link_dict = NULL;
dict_free(ctx->node_dict, lsdb_free_node);
ctx->node_dict = NULL;
timer_flush_root(&ctx->timer_root);
lsdb_free_name(&ctx->instance_name);
lsdb_free_name(&ctx->protocol_name);
lsdb_free_name(&ctx->topology_name);
@@ -837,6 +837,11 @@ lsdb_delete_ctx(struct lsdb_ctx_ *ctx)
ctx->ctrl_io_buf.data = NULL;
}
if (ctx->ctrl_socket_sockfd > 0) {
close(ctx->ctrl_socket_sockfd);
ctx->ctrl_socket_sockfd = 0;
}
free(ctx);
}