diff options
author | Karel Zak | 2010-06-17 10:29:33 +0200 |
---|---|---|
committer | Karel Zak | 2010-06-17 10:29:33 +0200 |
commit | 3e16599a3405b045e55388eb87853b7054aa8d79 (patch) | |
tree | 66267349d48f81e0a0df18cc4add15bd9b32be6f /disk-utils/mkswap.c | |
parent | wipefs: fix memory leaks (diff) | |
download | kernel-qcow2-util-linux-3e16599a3405b045e55388eb87853b7054aa8d79.tar.gz kernel-qcow2-util-linux-3e16599a3405b045e55388eb87853b7054aa8d79.tar.xz kernel-qcow2-util-linux-3e16599a3405b045e55388eb87853b7054aa8d79.zip |
mkswap: use calloc(), remove obsolete v1 header usage
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'disk-utils/mkswap.c')
-rw-r--r-- | disk-utils/mkswap.c | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/disk-utils/mkswap.c b/disk-utils/mkswap.c index acfd513e1..25a920ad5 100644 --- a/disk-utils/mkswap.c +++ b/disk-utils/mkswap.c @@ -145,7 +145,6 @@ is_sparc64(void) { static int user_pagesize; static int pagesize; static unsigned long *signature_page = NULL; -struct swap_header_v1 *p; static void init_signature_page(void) { @@ -167,9 +166,12 @@ init_signature_page(void) { "instead of the system value %d\n"), pagesize, kernel_pagesize); - signature_page = (unsigned long *) malloc(pagesize); - memset(signature_page, 0, pagesize); - p = (struct swap_header_v1 *) signature_page; + signature_page = (unsigned long *) calloc(1, pagesize); + if (!signature_page) { + fprintf(stderr, _("%s: calloc() failed: %s\n"), + program_name, strerror(errno)); + exit(1); + } } static void @@ -294,6 +296,8 @@ die(const char *str) { static void page_bad(int page) { + struct swap_header_v1_2 *p = (struct swap_header_v1_2 *) signature_page; + if (badpages == MAX_BADPAGES) die(_("too many bad pages")); p->badpages[badpages] = page; @@ -439,6 +443,7 @@ zap_bootbits(int fd, const char *devname, int force, int is_blkdev) int main(int argc, char ** argv) { struct stat statbuf; + struct swap_header_v1_2 *hdr; int i; unsigned long long maxpages; unsigned long long goodpages; @@ -627,9 +632,10 @@ main(int argc, char ** argv) { zap_bootbits(DEV, device_name, force, S_ISBLK(statbuf.st_mode)); - p->version = 1; - p->last_page = PAGES-1; - p->nr_badpages = badpages; + hdr = (struct swap_header_v1_2 *) signature_page; + hdr->version = 1; + hdr->last_page = PAGES - 1; + hdr->nr_badpages = badpages; if (badpages > PAGES - MIN_GOODPAGES) die(_("Unable to set up swap-space: unreadable")); |