summaryrefslogtreecommitdiff
path: root/disk-utils/mkswap.c
diff options
context:
space:
mode:
authorKarel Zak <kzak@redhat.com>2009-09-07 08:59:27 +0200
committerKarel Zak <kzak@redhat.com>2009-09-07 08:59:27 +0200
commit3216beb062707fd8a078ae5991fb17831399865b (patch)
treef7a7a8d5d6b257862dfe5f244f835e27fe23e682 /disk-utils/mkswap.c
parentadda7f7ecd53eef1074d8ea531b635c322507a7f (diff)
downloadutil-linux-old-3216beb062707fd8a078ae5991fb17831399865b.tar.gz
mkswap: fix memory leaks, cleanup check_blocks()
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'disk-utils/mkswap.c')
-rw-r--r--disk-utils/mkswap.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/disk-utils/mkswap.c b/disk-utils/mkswap.c
index bdfa8f7a..9feb2111 100644
--- a/disk-utils/mkswap.c
+++ b/disk-utils/mkswap.c
@@ -141,7 +141,7 @@ is_sparc64(void) {
*/
static int user_pagesize;
static int pagesize;
-static unsigned long *signature_page;
+static unsigned long *signature_page = NULL;
struct swap_header_v1 *p;
static void
@@ -170,6 +170,11 @@ init_signature_page(void) {
}
static void
+deinit_signature_page(void) {
+ free(signature_page);
+}
+
+static void
write_signature(char *sig) {
char *sp = (char *) signature_page;
@@ -303,20 +308,18 @@ check_blocks(void) {
die(_("Out of memory"));
current_page = 0;
while (current_page < PAGES) {
- if (!check)
- continue;
if (do_seek && lseek(DEV,current_page*pagesize,SEEK_SET) !=
current_page*pagesize)
die(_("seek failed in check_blocks"));
- if ((do_seek = (pagesize != read(DEV, buffer, pagesize)))) {
+ if ((do_seek = (pagesize != read(DEV, buffer, pagesize))))
page_bad(current_page);
- }
current_page++;
}
if (badpages == 1)
printf(_("one bad page\n"));
else if (badpages > 1)
printf(_("%lu bad pages\n"), badpages);
+ free(buffer);
}
/* return size in pages */
@@ -523,6 +526,7 @@ main(int argc, char ** argv) {
#endif
init_signature_page(); /* get pagesize */
+ atexit(deinit_signature_page);
if (!device_name) {
fprintf(stderr,