From 05eac44c0ec936331527ec9cf86fb040707129ab Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Mon, 7 Oct 2024 08:54:49 +1000 Subject: [PATCH] opendir: fix leak of cb_data on session failures Signed-off-by: Ronnie Sahlberg --- lib/libsmb2.c | 1 + lib/sync.c | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/libsmb2.c b/lib/libsmb2.c index c03223b2..e64e3a76 100644 --- a/lib/libsmb2.c +++ b/lib/libsmb2.c @@ -227,6 +227,7 @@ free_smb2dir(struct smb2_context *smb2, struct smb2dir *dir) free(dir->entries); dir->entries = e; } + free(dir->cb_data); free(dir); } diff --git a/lib/sync.c b/lib/sync.c index 270dedfe..c67c8a83 100644 --- a/lib/sync.c +++ b/lib/sync.c @@ -182,7 +182,6 @@ static void opendir_cb(struct smb2_context *smb2, int status, struct sync_cb_data *cb_data = private_data; if (cb_data->status == SMB2_STATUS_CANCELLED) { - free(cb_data); return; } @@ -201,6 +200,7 @@ struct smb2dir *smb2_opendir(struct smb2_context *smb2, const char *path) return NULL; } + /* smb2dir takes wnership of cb_data on success */ if (smb2_opendir_async(smb2, path, opendir_cb, cb_data) != 0) { smb2_set_error(smb2, "smb2_opendir_async failed"); @@ -214,7 +214,6 @@ struct smb2dir *smb2_opendir(struct smb2_context *smb2, const char *path) } ptr = cb_data->ptr; - free(cb_data); return ptr; }