[PATCH/RFC V2 06/26] main: Introduce xstrdup() function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This will abort on error, instead of causing a segfault.

Signed-off-by: Kevin Cernekee <cernekee at gmail.com>
---
 main.c |   12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/main.c b/main.c
index b3b1776..03ba644 100644
--- a/main.c
+++ b/main.c
@@ -366,9 +366,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 */
-- 
1.7.9.5




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux