aboutsummaryrefslogtreecommitdiffstats
path: root/src/ck.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ck.c')
-rw-r--r--src/ck.c27
1 files changed, 8 insertions, 19 deletions
diff --git a/src/ck.c b/src/ck.c
index 0d093d3..b2119e7 100644
--- a/src/ck.c
+++ b/src/ck.c
@@ -33,45 +33,32 @@
#include "cklist.h"
#include "ckutil.h"
-void free_res(UserOpt *opt, Conf *conf) {
- if (opt) {
- free_user_opt(opt);
- }
- if (conf) {
- free_conf(conf);
- }
-}
-
int main(int argc, char *argv[]) {
UserOpt opt;
+ Conf conf = {.VC_dir = NULL, .SCRT_dir = NULL};
/* get user opt */
switch(parse_action(argc, argv, &opt)) {
case APR_HELP:
- free_res(&opt, NULL);
print_parser_help();
- return 0;
+ goto error;
case APR_ERR:
print_parser_error(&opt);
- free_res(&opt, NULL);
- return 1;
+ goto error;
case APR_OK:
break;
}
- Conf conf = {.VC_dir = NULL, .SCRT_dir = NULL};
/* If the action is init don't load the config, skip to running init*/
if (opt.action != CKA_INIT) {
/* If the db doesn't exist ck is not initialized in the config
* location specified in opt */
if (!db_exists(&opt)) {
printf("ck is not initialized in %s.\nRun ck init first.\n", opt.confDir);
- free_res(&opt, NULL);
- return 1;
+ goto error;
}
/* Finally parse the config file and exit on error */
if (!config_file_parse(&conf, &opt)) {
- free_res(&opt, &conf);
- return 1;
+ goto error;
}
}
@@ -86,6 +73,8 @@ int main(int argc, char *argv[]) {
default:
break;
}
- free_res(&opt, &conf);
+ error:
+ free_user_opt(&opt);
+ free_conf(&conf);
return 0;
}