summaryrefslogtreecommitdiff
path: root/extra/innochecksum.cc
diff options
context:
space:
mode:
authorSergei Golubchik <serg@mariadb.org>2015-12-21 21:24:22 +0100
committerSergei Golubchik <serg@mariadb.org>2015-12-21 21:24:22 +0100
commita2bcee626d4ef2836e38e4932305871390164644 (patch)
treeb41e357427318bad8985078b91bbd2b0360defc8 /extra/innochecksum.cc
parent1788bfe93a745582d938a608d5959b7d2e6b2f23 (diff)
parent4fdf25afa8188905653a83e08fc387243e584600 (diff)
downloadmariadb-git-a2bcee626d4ef2836e38e4932305871390164644.tar.gz
Merge branch '10.0' into 10.1
Diffstat (limited to 'extra/innochecksum.cc')
-rw-r--r--extra/innochecksum.cc86
1 files changed, 30 insertions, 56 deletions
diff --git a/extra/innochecksum.cc b/extra/innochecksum.cc
index 687fc815d6d..f3ba4234d2e 100644
--- a/extra/innochecksum.cc
+++ b/extra/innochecksum.cc
@@ -1,5 +1,5 @@
/*
- Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
+ Copyright (c) 2005, 2012, Oracle and/or its affiliates.
Copyright (c) 2014, 2015, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify
@@ -663,8 +663,8 @@ int main(int argc, char **argv)
{
FILE* f; /* our input file */
char* filename; /* our input filename. */
- unsigned char *big_buf, *buf;
- unsigned char *big_xdes, *xdes;
+ unsigned char *big_buf= 0, *buf;
+ unsigned char *big_xdes= 0, *xdes;
ulong bytes; /* bytes read count */
ulint ct; /* current page number (0 based) */
time_t now; /* current time */
@@ -694,14 +694,14 @@ int main(int argc, char **argv)
if (*filename == '\0')
{
fprintf(stderr, "Error; File name missing\n");
- return 1;
+ goto error;
}
/* stat the file to get size and page count */
if (stat(filename, &st))
{
fprintf(stderr, "Error; %s cannot be found\n", filename);
- return 1;
+ goto error;
}
size= st.st_size;
@@ -711,7 +711,7 @@ int main(int argc, char **argv)
{
fprintf(stderr, "Error; %s cannot be opened", filename);
perror(" ");
- return 1;
+ goto error;
}
big_buf = (unsigned char *)malloc(2 * UNIV_PAGE_SIZE_MAX);
@@ -719,7 +719,7 @@ int main(int argc, char **argv)
{
fprintf(stderr, "Error; failed to allocate memory\n");
perror("");
- return 1;
+ goto error;
}
/* Make sure the page is aligned */
@@ -740,10 +740,7 @@ int main(int argc, char **argv)
if (!get_page_size(f, buf, &logical_page_size, &physical_page_size))
- {
- free(big_buf);
- return 1;
- }
+ goto error;
if (compressed)
{
@@ -763,8 +760,7 @@ int main(int argc, char **argv)
if (verbose)
printf("Number of pages: ");
printf("%lu\n", pages);
- free(big_buf);
- return 0;
+ goto ok;
}
else if (verbose)
{
@@ -790,9 +786,7 @@ int main(int argc, char **argv)
if (!fd)
{
perror("Error; Unable to obtain file descriptor number");
- free(big_buf);
- free(big_xdes);
- return 1;
+ goto error;
}
offset= (off_t)start_page * (off_t)physical_page_size;
@@ -800,9 +794,7 @@ int main(int argc, char **argv)
if (lseek(fd, offset, SEEK_SET) != offset)
{
perror("Error; Unable to seek to necessary offset");
- free(big_buf);
- free(big_xdes);
- return 1;
+ goto error;
}
}
@@ -816,20 +808,13 @@ int main(int argc, char **argv)
bytes= fread(buf, 1, physical_page_size, f);
if (!bytes && feof(f))
- {
- print_stats();
- free(big_buf);
- free(big_xdes);
- return 0;
- }
+ goto ok;
if (ferror(f))
{
fprintf(stderr, "Error reading %lu bytes", physical_page_size);
perror(" ");
- free(big_buf);
- free(big_xdes);
- return 1;
+ goto error;
}
ulint page_type = mach_read_from_2(buf+FIL_PAGE_TYPE);
@@ -883,11 +868,7 @@ int main(int argc, char **argv)
if (!page_zip_verify_checksum(buf, physical_page_size)) {
fprintf(stderr, "Fail; page %lu invalid (fails compressed page checksum).\n", ct);
if (!skip_corrupt)
- {
- free(big_buf);
- free(big_xdes);
- return 1;
- }
+ goto error;
page_ok = 0;
}
}
@@ -918,11 +899,7 @@ int main(int argc, char **argv)
{
fprintf(stderr, "Fail; page %lu invalid (fails log sequence number check)\n", ct);
if (!skip_corrupt)
- {
- free(big_buf);
- free(big_xdes);
- return 1;
- }
+ goto error;
page_ok = 0;
}
@@ -935,11 +912,7 @@ int main(int argc, char **argv)
{
fprintf(stderr, "Fail; page %lu invalid (fails old style checksum)\n", ct);
if (!skip_corrupt)
- {
- free(big_buf);
- free(big_xdes);
- return 1;
- }
+ goto error;
page_ok = 0;
}
}
@@ -959,22 +932,13 @@ int main(int argc, char **argv)
{
fprintf(stderr, "Fail; page %lu invalid (fails innodb and crc32 checksum)\n", ct);
if (!skip_corrupt)
- {
- free(big_buf);
- free(big_xdes);
- return 1;
- }
+ goto error;
page_ok = 0;
}
}
/* end if this was the last page we were supposed to check */
if (use_end_page && (ct >= end_page))
- {
- print_stats();
- free(big_buf);
- free(big_xdes);
- return 0;
- }
+ goto ok;
if (per_page_details)
{
@@ -1013,8 +977,18 @@ int main(int argc, char **argv)
}
}
}
- print_stats();
+
+ok:
+ if (!just_count)
+ print_stats();
+ free(big_xdes);
free(big_buf);
+ my_end(0);
+ exit(0);
+
+error:
free(big_xdes);
- return 0;
+ free(big_buf);
+ my_end(0);
+ exit(1);
}