ntfs: fixed coverity resource leaks.

* CID 5723, 5724, 5725, 5726, 5728, 5736, 5737
This commit is contained in:
Jérôme Duval 2012-04-08 23:33:15 +02:00
parent 3e0b63a489
commit 05326911fc
4 changed files with 14 additions and 5 deletions

View File

@ -271,7 +271,8 @@ fs_mount(fs_volume *_vol, const char *device, ulong flags, const char *args,
ntfs_calc_free_space(ns); ntfs_calc_free_space(ns);
} }
} }
} } else
free(ns);
exit: exit:
ERROR("fs_mount - EXIT, result code is %s\n", strerror(result)); ERROR("fs_mount - EXIT, result code is %s\n", strerror(result));
@ -978,6 +979,7 @@ exit:
ntfs_inode_close(ni); ntfs_inode_close(ni);
if (bi) if (bi)
ntfs_inode_close(bi); ntfs_inode_close(bi);
free(uname);
TRACE("fs_create - EXIT, result is %s\n", strerror(result)); TRACE("fs_create - EXIT, result is %s\n", strerror(result));
@ -1384,6 +1386,8 @@ exit:
ntfs_inode_close(sym); ntfs_inode_close(sym);
if (bi) if (bi)
ntfs_inode_close(bi); ntfs_inode_close(bi);
free(utarget);
free(uname);
TRACE("fs_symlink - EXIT, result is %s\n", strerror(result)); TRACE("fs_symlink - EXIT, result is %s\n", strerror(result));
@ -1444,7 +1448,6 @@ fs_mkdir(fs_volume *_vol, fs_vnode *_dir, const char *name, int perms)
newNode = (vnode*)ntfs_calloc(sizeof(vnode)); newNode = (vnode*)ntfs_calloc(sizeof(vnode));
if (newNode == NULL) { if (newNode == NULL) {
result = ENOMEM; result = ENOMEM;
ntfs_inode_close(ni);
goto exit; goto exit;
} }
@ -1469,6 +1472,7 @@ exit:
ntfs_inode_close(ni); ntfs_inode_close(ni);
if (bi) if (bi)
ntfs_inode_close(bi); ntfs_inode_close(bi);
free(uname);
TRACE("fs_mkdir - EXIT, result is %s\n", strerror(result)); TRACE("fs_mkdir - EXIT, result is %s\n", strerror(result));

View File

@ -92,7 +92,7 @@ fs_opendir(fs_volume *_vol, fs_vnode *_node, void** _cookie)
{ {
nspace *ns = (nspace*)_vol->private_volume; nspace *ns = (nspace*)_vol->private_volume;
vnode *node = (vnode*)_node->private_node; vnode *node = (vnode*)_node->private_node;
dircookie *cookie = (dircookie*)ntfs_calloc(sizeof(dircookie)); dircookie *cookie = NULL;
int result = B_NO_ERROR; int result = B_NO_ERROR;
ntfs_inode *ni = NULL; ntfs_inode *ni = NULL;
@ -111,6 +111,7 @@ fs_opendir(fs_volume *_vol, fs_vnode *_node, void** _cookie)
goto exit; goto exit;
} }
cookie = (dircookie*)ntfs_calloc(sizeof(dircookie));
if (cookie != NULL) { if (cookie != NULL) {
cookie->pos = 0; cookie->pos = 0;
cookie->ino = 0; cookie->ino = 0;

View File

@ -578,7 +578,7 @@ int utils_attr_get_name(ntfs_volume *vol, ATTR_RECORD *attr, char *buffer, int b
attrdef = ntfs_attr_find_in_attrdef(vol, attr->type); attrdef = ntfs_attr_find_in_attrdef(vol, attr->type);
if (attrdef) { if (attrdef) {
name = NULL; name = NULL;
namelen = ntfs_ucsnlen(attrdef->name, sizeof(attrdef->name)); namelen = ntfs_ucsnlen(attrdef->name, sizeof(attrdef->name));
if (ntfs_ucstombs(attrdef->name, namelen, &name, 0) < 0) { if (ntfs_ucstombs(attrdef->name, namelen, &name, 0) < 0) {
ntfs_log_error("Couldn't translate attribute type to current locale.\n"); ntfs_log_error("Couldn't translate attribute type to current locale.\n");
@ -593,17 +593,20 @@ int utils_attr_get_name(ntfs_volume *vol, ATTR_RECORD *attr, char *buffer, int b
if (len >= bufsize) { if (len >= bufsize) {
ntfs_log_error("Attribute type was truncated.\n"); ntfs_log_error("Attribute type was truncated.\n");
free(name);
return 0; return 0;
} }
if (!attr->name_length) { if (!attr->name_length) {
free(name);
return 0; return 0;
} }
buffer += len; buffer += len;
bufsize -= len; bufsize -= len;
name = NULL; free(name);
name = NULL;
namelen = attr->name_length; namelen = attr->name_length;
if (ntfs_ucstombs((ntfschar *)((char *)attr + attr->name_offset), if (ntfs_ucstombs((ntfschar *)((char *)attr + attr->name_offset),
namelen, &name, 0) < 0) { namelen, &name, 0) < 0) {

View File

@ -216,6 +216,7 @@ int ntfs_change_label(ntfs_volume *vol, char *label)
} }
result = 0; result = 0;
err_out: err_out:
ntfs_attr_put_search_ctx(ctx);
free(new_label); free(new_label);
return result; return result;
} }