Skip to content
Snippets Groups Projects
Commit df358867 authored by Daniel Salzman's avatar Daniel Salzman
Browse files

kzonecheck: fix memory leak

parent 2a223942
Branches
Tags
No related merge requests found
......@@ -32,7 +32,7 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
..
.SH SYNOPSIS
.sp
\fBkzonecheck\fP [\fIoptions\fP] \fIzone\-file\fP
\fBkzonecheck\fP [\fIoptions\fP] \fIfilename\fP
.SH DESCRIPTION
.sp
The utility checks zone file syntax and runs semantic checks on the zone
......@@ -59,7 +59,7 @@ Print the program version.
.UNINDENT
.SH SEE ALSO
.sp
\fBknotd(8)\fP, \fBknot.conf(5)\fP
\fBknotd(8)\fP, \fBknot.conf(5)\fP\&.
.SH AUTHOR
CZ.NIC Labs <http://www.knot-dns.cz>
.SH COPYRIGHT
......
......@@ -6,7 +6,7 @@ kzonecheck – Knot DNS zone file checking tool
Synopsis
--------
:program:`kzonecheck` [*options*] *zone-file*
:program:`kzonecheck` [*options*] *filename*
Description
-----------
......@@ -19,7 +19,7 @@ Please, refer to the ``semantic-checks`` configuration option in
:manpage:`knot.conf(5)` for the full list of available semantic checks.
Options
..........
.......
**-o**, **--origin** *origin*
Zone origin. If not specified, the origin is determined from the file name
......@@ -37,4 +37,4 @@ Options
See Also
--------
:manpage:`knotd(8)`, :manpage:`knot.conf(5)`
:manpage:`knotd(8)`, :manpage:`knot.conf(5)`.
......@@ -28,23 +28,21 @@
static void print_help(void)
{
printf("Usage: %s [parameters] <zonefile>\n"
printf("Usage: %s [parameters] <filename>\n"
"\n"
"Parameters:\n"
" -o, --origin <zone_origin> Zone name\n"
" (default filename or\n"
" filename without trailing .zone)\n"
" -v, --verbose Enable debug output.\n"
" -h, --help Print the program help.\n"
" -V, --version Print the program version.\n"
" -o, --origin <zone_origin> Zone name.\n"
" (default filename or filename without .zone)\n"
" -v, --verbose Enable debug output.\n"
" -h, --help Print the program help.\n"
" -V, --version Print the program version.\n"
"\n",
PROGRAM_NAME);
}
int main(int argc, char *argv[])
{
char *filename = NULL;
char *zonename = NULL;
const char *origin = NULL;
bool verbose = false;
FILE *outfile = stdout;
......@@ -58,11 +56,11 @@ int main(int argc, char *argv[])
};
/* Parse command line arguments */
int opt = 0, li = 0;
while ((opt = getopt_long(argc, argv, "o:vVh", opts, &li)) != -1) {
int opt = 0;
while ((opt = getopt_long(argc, argv, "o:vVh", opts, NULL)) != -1) {
switch (opt) {
case 'o':
zonename = strdup(optarg);
origin = optarg;
break;
case 'v':
verbose = true;
......@@ -86,15 +84,20 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
}
filename = argv[optind];
char *filename = argv[optind];
if (zonename == NULL) {
/* Get zone name from file name */
char *zonename;
if (origin == NULL) {
/* Get zone name from file name. */
const char *ext = ".zone";
zonename = basename(filename);
if (strcmp(zonename + strlen(zonename) - strlen(ext), ext) == 0) {
zonename = strndup(zonename, strlen(zonename) - strlen(ext));
} else {
zonename = strdup(zonename);
}
} else {
zonename = strdup(origin);
}
/* TODO: Remove logging from zone loading. */
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment