From: Theodore Ts'o Date: Wed, 7 May 2003 12:35:38 +0000 (-0400) Subject: badblocks.c (test_rw): Fix minor memory leak with test_rw() is X-Git-Tag: E2FSPROGS-1_34-WIP-0521~19 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6d40f568cdec7d654691e6eed61cf5a32e918c03;p=thirdparty%2Fe2fsprogs.git badblocks.c (test_rw): Fix minor memory leak with test_rw() is called for multiple passes. (test_nd): Fix bug in chosing randomness for the non-destructive test. We were only using 1 bit of randomness per byte instead of 8 due to a bit-shift bug. Also, initialize the random number generator from the time in main(). Thanks to Thayne Harbaugh for pointing out these bugs. --- diff --git a/misc/ChangeLog b/misc/ChangeLog index dc6fa3be8..aeb5e163c 100644 --- a/misc/ChangeLog +++ b/misc/ChangeLog @@ -1,3 +1,14 @@ +2003-05-07 Theodore Ts'o + + * badblocks.c (test_rw): Fix minor memory leak with test_rw() is + called for multiple passes. + (test_nd): Fix bug in chosing randomness for the + non-destructive test. We were only using 1 bit of + randomness per byte instead of 8 due to a bit-shift bug. + Also, initialize the random number generator from the time + in main(). Thanks to Thayne Harbaugh for pointing out + these bugs. + 2003-05-05 Theodore Ts'o * tune2fs.c (main, add_journal_device, remove_journal_device): If diff --git a/misc/badblocks.c b/misc/badblocks.c index 5afdd3f34..72ec2f95f 100644 --- a/misc/badblocks.c +++ b/misc/badblocks.c @@ -43,6 +43,7 @@ extern int optind; #include #include #include +#include #include #include @@ -382,6 +383,7 @@ static unsigned int test_rw (int dev, unsigned long last_block, flush_bufs(); } + free(buffer); return bb_count; } @@ -431,7 +433,7 @@ static unsigned int test_nd (int dev, unsigned long last_block, for(ptr = blkbuf + blocks_at_once * block_size; ptr < blkbuf + 2 * blocks_at_once * block_size; ++ptr) { - (*ptr) = random() % (1 << sizeof(char)); + (*ptr) = random() % (1 << (8 * sizeof(char))); } flush_bufs(); @@ -656,6 +658,7 @@ int main (int argc, char ** argv) bindtextdomain(NLS_CAT_NAME, LOCALEDIR); textdomain(NLS_CAT_NAME); #endif + srandom((unsigned int)time(NULL)); /* simple randomness is enough */ test_func = test_ro; if (argc && *argv)