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
|
// Default file
|
||||||
case 'D':
|
case 'D':
|
||||||
cfg->servers->ip = optarg;
|
cfg->servers->default_file = optarg;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// PID file
|
// 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],
|
printf("%s: Invalid value for '--%s'\n", argv[0],
|
||||||
options[optindex].name);
|
options[optindex].name);
|
||||||
break;
|
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)
|
void config_destroy(struct config *config)
|
||||||
{
|
{
|
||||||
|
string_destroy(config->servers->server_name);
|
||||||
free(config->servers);
|
free(config->servers);
|
||||||
free(config);
|
free(config);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,7 @@ void string_concat_str(struct string *str, const char *to_concat, size_t size)
|
||||||
if (new_size == 0)
|
if (new_size == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
str->size = new_size;
|
||||||
str->data = realloc(str->data, new_size);
|
str->data = realloc(str->data, new_size);
|
||||||
if (str->data == NULL)
|
if (str->data == NULL)
|
||||||
return; // Handle ?
|
return; // Handle ?
|
||||||
|
|
@ -65,6 +66,12 @@ void string_concat_str(struct string *str, const char *to_concat, size_t size)
|
||||||
|
|
||||||
void string_destroy(struct string *str)
|
void string_destroy(struct string *str)
|
||||||
{
|
{
|
||||||
free(str->data);
|
if (str != NULL)
|
||||||
free(str);
|
{
|
||||||
|
if (str->data != NULL)
|
||||||
|
{
|
||||||
|
free(str->data);
|
||||||
|
}
|
||||||
|
free(str);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue