From 13ab497b7ce574b4844caef31c85643c57430348 Mon Sep 17 00:00:00 2001 From: szaka Date: Wed, 8 Nov 2006 20:00:28 +0000 Subject: [PATCH] ntfs_attr_rm(): fix inconsistent deallocation of *na; adapt its users --- libntfs-3g/attrib.c | 9 ++------- libntfs-3g/dir.c | 23 +++++++++++++++-------- src/ntfs-3g.c | 12 +++++------- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/libntfs-3g/attrib.c b/libntfs-3g/attrib.c index e35f220d..6325f307 100644 --- a/libntfs-3g/attrib.c +++ b/libntfs-3g/attrib.c @@ -3080,15 +3080,13 @@ add_attr_record: (val && (ntfs_attr_pwrite(na, 0, size, val) != size))) { err = errno; ntfs_log_trace("Failed to initialize just added attribute.\n"); - if (ntfs_attr_rm(na)) { + if (ntfs_attr_rm(na)) ntfs_log_trace("Failed to remove just added attribute. " "Probably leaving inconstant metadata.\n"); - ntfs_attr_close(na); - } + ntfs_attr_close(na); goto err_out; } ntfs_attr_close(na); - /* Done !*/ return 0; rm_attr_err_out: @@ -3164,9 +3162,6 @@ int ntfs_attr_rm(ntfs_attr *na) ret = -1; } - /* Throw away now non-exist attribute. */ - ntfs_attr_close(na); - /* Done. */ return ret; } diff --git a/libntfs-3g/dir.c b/libntfs-3g/dir.c index 328a7bfb..dca17193 100644 --- a/libntfs-3g/dir.c +++ b/libntfs-3g/dir.c @@ -1230,10 +1230,13 @@ err_out: ntfs_log_perror("Failed to open SD (0x50) attribute of " " inode 0x%llx. Run chkdsk.\n", (unsigned long long)ni->mft_no); - else if (ntfs_attr_rm(na)) - ntfs_log_perror("Failed to remove SD (0x50) attribute " - "of inode 0x%llx. Run chkdsk.\n", - (unsigned long long)ni->mft_no); + else { + if (ntfs_attr_rm(na)) + ntfs_log_perror("Failed to remove SD (0x50) " + "attribute of inode 0x%llx", + (unsigned long long)ni->mft_no); + ntfs_attr_close(na); + } } if (rollback_data) { ntfs_attr *na; @@ -1243,10 +1246,14 @@ err_out: ntfs_log_perror("Failed to open data attribute of " " inode 0x%llx. Run chkdsk.\n", (unsigned long long)ni->mft_no); - else if (ntfs_attr_rm(na)) - ntfs_log_perror("Failed to remove data attribute of " - "inode 0x%llx. Run chkdsk.\n", - (unsigned long long)ni->mft_no); + else { + if (ntfs_attr_rm(na)) + ntfs_log_perror("Failed to remove data " + "attribute of inode 0x%llx", + (unsigned long long)ni->mft_no); + + ntfs_attr_close(na); + } } /* * Free extent MFT records (should not exist any with current diff --git a/src/ntfs-3g.c b/src/ntfs-3g.c index 10e2e085..9e9b6fe6 100644 --- a/src/ntfs-3g.c +++ b/src/ntfs-3g.c @@ -1016,10 +1016,10 @@ static int ntfs_fuse_rm_stream(const char *path, ntfschar *stream_name, res = -errno; goto exit; } - if (ntfs_attr_rm(na)) { + if (ntfs_attr_rm(na)) res = -errno; - ntfs_attr_close(na); - } + + ntfs_attr_close(na); exit: if (ntfs_inode_close(ni)) ntfs_log_perror("Failed to close inode"); @@ -1478,11 +1478,9 @@ static int ntfs_fuse_removexattr(const char *path, const char *name) ntfs_fuse_mark_free_space_outdated(); if (ntfs_attr_rm(na)) res = -errno; - else - na = NULL; + + ntfs_attr_close(na); exit: - if (na) - ntfs_attr_close(na); free(lename); if (ntfs_inode_close(ni)) ntfs_log_perror("Failed to close inode");