]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
badblocks.c (test_rw): Fix minor memory leak with test_rw() is
authorTheodore Ts'o <tytso@mit.edu>
Wed, 7 May 2003 12:35:38 +0000 (08:35 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Wed, 7 May 2003 12:35:38 +0000 (08:35 -0400)
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.

misc/ChangeLog
misc/badblocks.c

index dc6fa3be850e50e11209fddd94ed1f46f1d2087e..aeb5e163c0b9dfc1d061dcf254fce9e360bfe93a 100644 (file)
@@ -1,3 +1,14 @@
+2003-05-07  Theodore Ts'o  <tytso@mit.edu>
+
+       * 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  <tytso@mit.edu>
 
        * tune2fs.c (main, add_journal_device, remove_journal_device): If
index 5afdd3f349359aba56665d7b4e30ed8c9e12d0ea..72ec2f95f25aa70b9bea92ea4ec14447c6152f77 100644 (file)
@@ -43,6 +43,7 @@ extern int optind;
 #include <string.h>
 #include <unistd.h>
 #include <setjmp.h>
+#include <time.h>
 
 #include <sys/ioctl.h>
 #include <sys/types.h>
@@ -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)