Fix memleak, develop proto_free functions for pop3 and smtp

fixes issue #72 reported by @applehxb
This commit is contained in:
Soner Tari 2024-07-11 11:35:45 +03:00
parent 9879c7ba49
commit 4a1c5b1d40
2 changed files with 32 additions and 2 deletions

View File

@ -83,12 +83,20 @@ protopop3_validate(pxy_conn_ctx_t *ctx, char *packet, size_t packet_size)
return 0;
}
static void NONNULL(1)
protopop3_free(pxy_conn_ctx_t *ctx)
{
protopop3_ctx_t *pop3_ctx = ctx->protoctx->arg;
free(pop3_ctx);
}
// @attention Called by thrmgr thread
protocol_t
protopop3_setup(pxy_conn_ctx_t *ctx)
{
ctx->protoctx->proto = PROTO_POP3;
ctx->protoctx->proto_free = protopop3_free;
ctx->protoctx->validatecb = protopop3_validate;
ctx->protoctx->arg = malloc(sizeof(protopop3_ctx_t));
@ -100,6 +108,13 @@ protopop3_setup(pxy_conn_ctx_t *ctx)
return PROTO_POP3;
}
static void NONNULL(1)
protopop3s_free(pxy_conn_ctx_t *ctx)
{
protopop3_free(ctx);
protossl_free(ctx);
}
// @attention Called by thrmgr thread
protocol_t
protopop3s_setup(pxy_conn_ctx_t *ctx)
@ -111,7 +126,7 @@ protopop3s_setup(pxy_conn_ctx_t *ctx)
ctx->protoctx->bev_eventcb = protossl_bev_eventcb;
ctx->protoctx->proto_free = protossl_free;
ctx->protoctx->proto_free = protopop3s_free;
ctx->protoctx->validatecb = protopop3_validate;
ctx->protoctx->arg = malloc(sizeof(protopop3_ctx_t));

View File

@ -299,6 +299,13 @@ protosmtps_bev_eventcb(struct bufferevent *bev, short events, void *arg)
}
}
static void NONNULL(1)
protosmtp_free(pxy_conn_ctx_t *ctx)
{
protosmtp_ctx_t *smtp_ctx = ctx->protoctx->arg;
free(smtp_ctx);
}
// @attention Called by thrmgr thread
protocol_t
protosmtp_setup(pxy_conn_ctx_t *ctx)
@ -310,6 +317,7 @@ protosmtp_setup(pxy_conn_ctx_t *ctx)
ctx->protoctx->bev_readcb = protosmtp_bev_readcb;
ctx->protoctx->bev_eventcb = protosmtp_bev_eventcb;
ctx->protoctx->proto_free = protosmtp_free;
ctx->protoctx->validatecb = protosmtp_validate;
ctx->protoctx->arg = malloc(sizeof(protosmtp_ctx_t));
@ -321,6 +329,13 @@ protosmtp_setup(pxy_conn_ctx_t *ctx)
return PROTO_SMTP;
}
static void NONNULL(1)
protosmtps_free(pxy_conn_ctx_t *ctx)
{
protosmtp_free(ctx);
protossl_free(ctx);
}
// @attention Called by thrmgr thread
protocol_t
protosmtps_setup(pxy_conn_ctx_t *ctx)
@ -333,7 +348,7 @@ protosmtps_setup(pxy_conn_ctx_t *ctx)
ctx->protoctx->bev_readcb = protosmtp_bev_readcb;
ctx->protoctx->bev_eventcb = protosmtps_bev_eventcb;
ctx->protoctx->proto_free = protossl_free;
ctx->protoctx->proto_free = protosmtps_free;
ctx->protoctx->validatecb = protosmtp_validate;
ctx->protoctx->arg = malloc(sizeof(protosmtp_ctx_t));