summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaksym Planeta <mcsim.planeta@gmail.com>2012-10-05 20:07:29 +0300
committerMaksym Planeta <mcsim.planeta@gmail.com>2012-10-28 12:33:35 +0100
commit3fb8db3ee9f5bf97c597a09af75a344e5c9b8d01 (patch)
treeb7b1db6339cd1e30066ff0f58d781e51ad03ff3c
parentc62283c1d680158a92f549231539ef6134b4ab65 (diff)
Fix bugs with initialization of variables, created on stack.
* ext2fs/balloc.c (ext2_new_block): Function changed. * ext2fs/ialloc.c (ext2_alloc_inode): Function changed.
-rw-r--r--ext2fs/balloc.c11
-rw-r--r--ext2fs/ialloc.c7
2 files changed, 16 insertions, 2 deletions
diff --git a/ext2fs/balloc.c b/ext2fs/balloc.c
index 8ad29cec..30c2eb8d 100644
--- a/ext2fs/balloc.c
+++ b/ext2fs/balloc.c
@@ -139,7 +139,7 @@ ext2_new_block (block_t goal,
block_t prealloc_goal,
block_t *prealloc_count, block_t *prealloc_block)
{
- char *bh;
+ char *bh = 0;
char *p, *r;
int i, j, k, tmp;
unsigned long lmap;
@@ -165,6 +165,7 @@ ext2_new_block (block_t goal,
ext2_debug ("goal=%u", goal);
repeat:
+ assert (! bh);
/*
* First, test whether the goal block is free.
*/
@@ -245,6 +246,7 @@ repeat:
j = k;
goto got_block;
}
+ bh = 0;
}
ext2_debug ("bit not found in block group %d", i);
@@ -277,12 +279,14 @@ repeat:
sblock->s_blocks_per_group);
if (j >= sblock->s_blocks_per_group)
{
+ bh = 0;
ext2_error ("free blocks count corrupted for block group %d", i);
spin_unlock (&global_lock);
return 0;
}
search_back:
+ assert (bh);
/*
* We have succeeded in finding a free byte in the block
* bitmap. Now search backwards up to 7 bits to find the
@@ -291,6 +295,7 @@ search_back:
for (k = 0; k < 7 && j > 0 && !test_bit (j - 1, bh); k++, j--);
got_block:
+ assert (bh);
ext2_debug ("using block group %d (%d)", i, gdp->bg_free_blocks_count);
@@ -304,6 +309,7 @@ got_block:
if (set_bit (j, bh))
{
ext2_warning ("bit already set for block %d", j);
+ bh = 0;
goto repeat;
}
@@ -351,6 +357,7 @@ got_block:
j = tmp;
record_global_poke (bh);
+ bh = 0;
if (j >= sblock->s_blocks_count)
{
@@ -363,12 +370,14 @@ got_block:
j, goal_hits, goal_attempts);
gdp->bg_free_blocks_count--;
+ disk_cache_block_ref_ptr (gdp);
record_global_poke (gdp);
sblock->s_free_blocks_count--;
sblock_dirty = 1;
sync_out:
+ assert (! bh);
spin_unlock (&global_lock);
alloc_sync (0);
diff --git a/ext2fs/ialloc.c b/ext2fs/ialloc.c
index 15c17a4e..6ba75822 100644
--- a/ext2fs/ialloc.c
+++ b/ext2fs/ialloc.c
@@ -111,7 +111,7 @@ diskfs_free_node (struct node *np, mode_t old_mode)
ino_t
ext2_alloc_inode (ino_t dir_inum, mode_t mode)
{
- char *bh;
+ char *bh = 0;
int i, j, inum, avefreei;
struct ext2_group_desc *gdp;
struct ext2_group_desc *tmp;
@@ -119,6 +119,7 @@ ext2_alloc_inode (ino_t dir_inum, mode_t mode)
spin_lock (&global_lock);
repeat:
+ assert (! bh);
gdp = NULL;
i = 0;
@@ -221,12 +222,15 @@ repeat:
if (set_bit (inum, bh))
{
ext2_warning ("bit already set for inode %d", inum);
+ bh = 0;
goto repeat;
}
record_global_poke (bh);
+ bh = 0;
}
else
{
+ bh = 0;
if (gdp->bg_free_inodes_count != 0)
{
ext2_error ("free inodes count corrupted in group %d", i);
@@ -254,6 +258,7 @@ repeat:
sblock_dirty = 1;
sync_out:
+ assert (! bh);
spin_unlock (&global_lock);
alloc_sync (0);