diff mbox

[pacman-dev] pacman-conf.c: exit if cannot set rootdir or parse config file

Message ID 20180217011057.28616-1-iff@escondida.tk
State Accepted, archived
Headers show

Commit Message

Ivy Foster Feb. 17, 2018, 1:10 a.m. UTC
From: Ivy Foster <iff@escondida.tk>

---
 src/pacman/pacman-conf.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Comments

Allan McRae March 14, 2018, 2:16 a.m. UTC | #1
On 17/02/18 11:10, iff@escondida.tk wrote:
> From: Ivy Foster <iff@escondida.tk>
> 
> ---
>  src/pacman/pacman-conf.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)

Thanks,
A
diff mbox

Patch

diff --git a/src/pacman/pacman-conf.c b/src/pacman/pacman-conf.c
index 4ffa24a3..aa0cdf22 100644
--- a/src/pacman/pacman-conf.c
+++ b/src/pacman/pacman-conf.c
@@ -77,7 +77,11 @@  static void parse_opts(int argc, char **argv)
 				config_file = optarg;
 				break;
 			case 'R':
-				config->rootdir = strdup(optarg);
+				if ((config->rootdir = strdup(optarg)) == NULL) {
+					fprintf(stderr, "error setting rootdir '%s': out of memory\n", optarg);
+					cleanup();
+					exit(1);
+				}
 				break;
 			case 'l':
 				repo_list = 1;
@@ -105,6 +109,8 @@  static void parse_opts(int argc, char **argv)
 
 	if(parseconfigfile(config_file) != 0 || setdefaults(config) != 0) {
 		fprintf(stderr, "error parsing '%s'\n", config_file);
+		cleanup();
+		exit(1);
 	}
 }