fix: small bugs in config parser and string utils
This commit is contained in:
parent
ffd4159725
commit
0982f2bf3a
2 changed files with 17 additions and 3 deletions
|
|
@ -117,7 +117,7 @@ static int handle_opt(char **argv, char opt, struct config *cfg)
|
|||
|
||||
// Default file
|
||||
case 'D':
|
||||
cfg->servers->ip = optarg;
|
||||
cfg->servers->default_file = optarg;
|
||||
break;
|
||||
|
||||
// PID file
|
||||
|
|
@ -167,6 +167,12 @@ static void print_arg_error(int err, char **argv, struct option options[],
|
|||
printf("%s: Invalid value for '--%s'\n", argv[0],
|
||||
options[optindex].name);
|
||||
break;
|
||||
|
||||
default:
|
||||
printf(
|
||||
"%s: An unknown error happened while trying to parse arguments\n",
|
||||
argv[0]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -229,6 +235,7 @@ struct config *parse_configuration(int argc, char *argv[])
|
|||
|
||||
void config_destroy(struct config *config)
|
||||
{
|
||||
string_destroy(config->servers->server_name);
|
||||
free(config->servers);
|
||||
free(config);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@ void string_concat_str(struct string *str, const char *to_concat, size_t size)
|
|||
if (new_size == 0)
|
||||
return;
|
||||
|
||||
str->size = new_size;
|
||||
str->data = realloc(str->data, new_size);
|
||||
if (str->data == NULL)
|
||||
return; // Handle ?
|
||||
|
|
@ -64,7 +65,13 @@ void string_concat_str(struct string *str, const char *to_concat, size_t size)
|
|||
}
|
||||
|
||||
void string_destroy(struct string *str)
|
||||
{
|
||||
if (str != NULL)
|
||||
{
|
||||
if (str->data != NULL)
|
||||
{
|
||||
free(str->data);
|
||||
}
|
||||
free(str);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue