mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-11-02 07:28:21 +00:00
ext2: fix memory leak
This commit is contained in:
@@ -236,6 +236,7 @@ static int changedircount(ext2fs_t *fs, int bg, int change) {
|
|||||||
// allocates either a block or an inode
|
// allocates either a block or an inode
|
||||||
static int allocatestructure(ext2fs_t *fs, uintmax_t *retid, bool inode) {
|
static int allocatestructure(ext2fs_t *fs, uintmax_t *retid, bool inode) {
|
||||||
MUTEX_ACQUIRE(&fs->descriptorlock, false);
|
MUTEX_ACQUIRE(&fs->descriptorlock, false);
|
||||||
|
uint8_t *bm = NULL;
|
||||||
uintmax_t bg = inode ? fs->lowestfreeinodebg : fs->lowestfreeblockbg;
|
uintmax_t bg = inode ? fs->lowestfreeinodebg : fs->lowestfreeblockbg;
|
||||||
|
|
||||||
int e = 0;
|
int e = 0;
|
||||||
@@ -270,7 +271,7 @@ static int allocatestructure(ext2fs_t *fs, uintmax_t *retid, bool inode) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t bmsize = (inode ? fs->superblock.inodespergroup : fs->superblock.blockspergroup) / 8;
|
size_t bmsize = (inode ? fs->superblock.inodespergroup : fs->superblock.blockspergroup) / 8;
|
||||||
uint8_t *bm = alloc(bmsize);
|
bm = alloc(bmsize);
|
||||||
if (bm == NULL) {
|
if (bm == NULL) {
|
||||||
e = ENOMEM;
|
e = ENOMEM;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@@ -338,6 +339,9 @@ static int allocatestructure(ext2fs_t *fs, uintmax_t *retid, bool inode) {
|
|||||||
ASSERT_UNCLEAN(fs, e == 0);
|
ASSERT_UNCLEAN(fs, e == 0);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
if (bm)
|
||||||
|
free(bm);
|
||||||
|
|
||||||
MUTEX_RELEASE(&fs->descriptorlock);
|
MUTEX_RELEASE(&fs->descriptorlock);
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
@@ -345,6 +349,7 @@ static int allocatestructure(ext2fs_t *fs, uintmax_t *retid, bool inode) {
|
|||||||
// frees a block or an inode
|
// frees a block or an inode
|
||||||
static int freestructure(ext2fs_t *fs, uintmax_t id, bool inode) {
|
static int freestructure(ext2fs_t *fs, uintmax_t id, bool inode) {
|
||||||
int e = 0;
|
int e = 0;
|
||||||
|
uint8_t *bm = NULL;
|
||||||
int bg = inode ? INODE_GETGROUP(fs, id) : BLOCK_GETGROUP(fs, id);
|
int bg = inode ? INODE_GETGROUP(fs, id) : BLOCK_GETGROUP(fs, id);
|
||||||
MUTEX_ACQUIRE(&fs->descriptorlock, false);
|
MUTEX_ACQUIRE(&fs->descriptorlock, false);
|
||||||
|
|
||||||
@@ -355,7 +360,7 @@ static int freestructure(ext2fs_t *fs, uintmax_t id, bool inode) {
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
size_t bmsize = (inode ? fs->superblock.inodespergroup : fs->superblock.blockspergroup) / 8;
|
size_t bmsize = (inode ? fs->superblock.inodespergroup : fs->superblock.blockspergroup) / 8;
|
||||||
uint8_t *bm = alloc(bmsize);
|
bm = alloc(bmsize);
|
||||||
if (bm == NULL) {
|
if (bm == NULL) {
|
||||||
e = ENOMEM;
|
e = ENOMEM;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@@ -409,6 +414,8 @@ static int freestructure(ext2fs_t *fs, uintmax_t id, bool inode) {
|
|||||||
MUTEX_RELEASE(&fs->superblocklock);
|
MUTEX_RELEASE(&fs->superblocklock);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
if (bm)
|
||||||
|
free(bm);
|
||||||
MUTEX_RELEASE(&fs->descriptorlock);
|
MUTEX_RELEASE(&fs->descriptorlock);
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user