ext2: fix memory leak
This commit is contained in:
parent
0eb461410c
commit
cd8d016f34
3 changed files with 18 additions and 5 deletions
|
|
@ -234,8 +234,9 @@ int ext2_open_file(struct fs *vfs, struct file *file, const char *path)
|
||||||
|
|
||||||
char *strtok_last = NULL;
|
char *strtok_last = NULL;
|
||||||
char *token = strtok(path_copy, "/", &strtok_last);
|
char *token = strtok(path_copy, "/", &strtok_last);
|
||||||
|
struct ext2_dir_entry *entry = kmalloc(fs->block_size, ALLOC_DMA);
|
||||||
|
void *oentry = entry;
|
||||||
while (token) {
|
while (token) {
|
||||||
struct ext2_dir_entry *entry = kmalloc(fs->block_size, ALLOC_DMA);
|
|
||||||
if (!entry) {
|
if (!entry) {
|
||||||
kfree(inode);
|
kfree(inode);
|
||||||
kfree(path_copy);
|
kfree(path_copy);
|
||||||
|
|
@ -260,14 +261,14 @@ int ext2_open_file(struct fs *vfs, struct file *file, const char *path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
found:
|
|
||||||
if (!entry || !entry->inode) {
|
if (!entry || !entry->inode) {
|
||||||
kfree(inode);
|
kfree(inode);
|
||||||
kfree(path_copy);
|
kfree(path_copy);
|
||||||
kfree(entry);
|
kfree(oentry);
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
found:
|
||||||
ext2_read_inode(fs, inode, entry->inode);
|
ext2_read_inode(fs, inode, entry->inode);
|
||||||
|
|
||||||
token = strtok(NULL, "/", &strtok_last);
|
token = strtok(NULL, "/", &strtok_last);
|
||||||
|
|
@ -279,6 +280,7 @@ found:
|
||||||
file->size = inode->size;
|
file->size = inode->size;
|
||||||
file->type = inode_to_ftype[inode->mode >> 12];
|
file->type = inode_to_ftype[inode->mode >> 12];
|
||||||
file->inode_num = inode_no;
|
file->inode_num = inode_no;
|
||||||
|
kfree(oentry);
|
||||||
|
|
||||||
/* check for long filesize */
|
/* check for long filesize */
|
||||||
if (fs->sb.feature_ro_compat & EXT2_FLAG_LONG_FILESIZE)
|
if (fs->sb.feature_ro_compat & EXT2_FLAG_LONG_FILESIZE)
|
||||||
|
|
|
||||||
13
fs/vfs.c
13
fs/vfs.c
|
|
@ -37,7 +37,7 @@ int open(const char *pathname, int flags)
|
||||||
int result = rootfs->ops.open(rootfs, &fd->file, pathname);
|
int result = rootfs->ops.open(rootfs, &fd->file, pathname);
|
||||||
|
|
||||||
if (result < 0) {
|
if (result < 0) {
|
||||||
kprintf(LOG_ERROR "Failed to open %s\n", pathname);
|
kprintf(LOG_ERROR "Failed to open %s: %s\n", pathname, strerror(-result));
|
||||||
return result;
|
return result;
|
||||||
} else if (result == VFSE_IS_BDEV) {
|
} else if (result == VFSE_IS_BDEV) {
|
||||||
/* TODO: continue search into mounted filesystems */
|
/* TODO: continue search into mounted filesystems */
|
||||||
|
|
@ -106,6 +106,9 @@ DIR *opendir(const char *name)
|
||||||
|
|
||||||
struct dirent *readdir(DIR *dir)
|
struct dirent *readdir(DIR *dir)
|
||||||
{
|
{
|
||||||
|
if(!dir)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
struct fs *fs = dir->fs;
|
struct fs *fs = dir->fs;
|
||||||
struct file *file = dir->file;
|
struct file *file = dir->file;
|
||||||
|
|
||||||
|
|
@ -154,5 +157,13 @@ void vfs_init(const char *rootdev_name)
|
||||||
|
|
||||||
/* init file descriptor slab */
|
/* init file descriptor slab */
|
||||||
fd_slab = slab_create(sizeof(struct file_descriptor), 16 * KB, 0);
|
fd_slab = slab_create(sizeof(struct file_descriptor), 16 * KB, 0);
|
||||||
|
|
||||||
|
DIR *dir = opendir("test/lol");
|
||||||
|
struct dirent *dirent;
|
||||||
|
|
||||||
|
kprintf("Root directory contents:\n");
|
||||||
|
while ((dirent = readdir(dir))) {
|
||||||
|
kprintf(LOG_DEBUG "Found file %s\n", dirent->name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue