summaryrefslogtreecommitdiffstats
path: root/src/ntfs_dir.c
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2008-11-13 09:24:59 +0100
committerChristophe Grenier <grenier@cgsecurity.org>2008-11-13 09:24:59 +0100
commitaf127dc90c383786b598d8fce215aa8c4d03b233 (patch)
treecc3b623f1329309b6b43aa2ca9bb73fa03a2abcd /src/ntfs_dir.c
parent3f13734b7f60e28be661fa747c73f44cca873175 (diff)
NTFS file copy: fix memory leak when copied failed.
Diffstat (limited to 'src/ntfs_dir.c')
-rw-r--r--src/ntfs_dir.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/ntfs_dir.c b/src/ntfs_dir.c
index 604f354..1ac3442 100644
--- a/src/ntfs_dir.c
+++ b/src/ntfs_dir.c
@@ -340,12 +340,16 @@ static int ntfs_copy(disk_t *disk_car, const partition_t *partition, dir_data_t
u32 block_size;
buffer = (char *)MALLOC(bufsize);
if (!buffer)
+ {
+ ntfs_inode_close(inode);
return -2;
+ }
attr = ntfs_attr_open(inode, AT_DATA, NULL, 0);
if (!attr)
{
log_error("Cannot find attribute type 0x%lx.\n", (long) AT_DATA);
free(buffer);
+ ntfs_inode_close(inode);
return -3;
}
if ((inode->mft_no < 2) && (attr->type == AT_DATA))
@@ -360,6 +364,9 @@ static int ntfs_copy(disk_t *disk_car, const partition_t *partition, dir_data_t
{
log_critical("Can't create file %s: %s\n",new_file, strerror(errno));
free(new_file);
+ ntfs_attr_close(attr);
+ free(buffer);
+ ntfs_inode_close(inode);
return -4;
}
offset = 0;
@@ -390,8 +397,8 @@ static int ntfs_copy(disk_t *disk_car, const partition_t *partition, dir_data_t
}
fclose(f_out);
set_date(new_file, file->stat.st_atime, file->stat.st_mtime);
- ntfs_attr_close(attr);
free(new_file);
+ ntfs_attr_close(attr);
free(buffer);
}
/* Finished with the inode; release it. */