From a83b017ea8f369756ef3cf9f09a35469c5157cea Mon Sep 17 00:00:00 2001 From: safocl Date: Thu, 30 Jan 2025 05:36:07 +0400 Subject: [PATCH] fix: memory leaks some code don't free allocated memory. --- ntfsprogs/ntfsfix.c | 12 ++++++------ ntfsprogs/ntfsusermap.c | 7 +++++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/ntfsprogs/ntfsfix.c b/ntfsprogs/ntfsfix.c index b214068f..a62b84a6 100644 --- a/ntfsprogs/ntfsfix.c +++ b/ntfsprogs/ntfsfix.c @@ -1204,11 +1204,11 @@ static int fix_self_located_mft(ntfs_volume *vol) ntfs_log_info(OK); res = -1; } - free(selfloc.mft0); - free(selfloc.mft1); - free(selfloc.mft2); - free(selfloc.attrlist); } + free(selfloc.mft0); + free(selfloc.mft1); + free(selfloc.mft2); + free(selfloc.attrlist); return (res); } @@ -1421,10 +1421,10 @@ static int check_alternate_boot(ntfs_volume *vol) } else { ntfs_log_info("Error : could not read the boot sector again\n"); } - free(full_bs); - free(alt_bs); error_exit : + free(full_bs); + free(alt_bs); return (res); } diff --git a/ntfsprogs/ntfsusermap.c b/ntfsprogs/ntfsusermap.c index 6c1f61b8..24a9c53a 100644 --- a/ntfsprogs/ntfsusermap.c +++ b/ntfsprogs/ntfsusermap.c @@ -781,7 +781,7 @@ static boolean outputmap(const char *volume, const char *dir) char buf[256]; int fn; char *fullname; - char *backup; + char *backup = NULL; struct USERMAPPING *mapping; boolean done; boolean err; @@ -895,6 +895,8 @@ static boolean outputmap(const char *volume, const char *dir) if (!done) fprintf(stderr, "* Could not create mapping file \"%s\"\n", fullname); + free(backup); + free(fullname); return (done); } @@ -1005,7 +1007,8 @@ static boolean sanitize(void) group->defined = AGREED; group->next = firstmapping; firstmapping = group; - } + } else + free(group); } } }