Skip to content

Commit

Permalink
main: Introduce xstrdup() function
Browse files Browse the repository at this point in the history
This will abort on error, instead of causing a segfault.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
  • Loading branch information
cernekee committed Jan 15, 2014
1 parent 654d565 commit 73ca062
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions main.c
Expand Up @@ -389,9 +389,21 @@ static int config_line_num = 0;
* For this we use the keep_config_arg() macro below.
* 3. It may be freed during normal operation, so we have to use strdup()
* even when it's an option from argv[]. (e.g. vpninfo->cert_password).
* For this we use the xstrdup() function below.
*/
#define keep_config_arg() (config_file && config_arg ? strdup(config_arg) : config_arg)

static char *xstrdup(const char *arg)
{
char *ret = strdup(arg);

if (!ret) {
fprintf(stderr, _("Failed to allocate string\n"));
exit(1);
}
return ret;
}

static int next_option(int argc, char **argv, char **config_arg)
{
/* These get re-used */
Expand Down

0 comments on commit 73ca062

Please sign in to comment.