From c6dd581ec561af04e4e0edb07bcf74e4db17485a Mon Sep 17 00:00:00 2001
From: Allan McRae <allan@archlinux.org>
Date: Mon, 22 Dec 2014 17:42:41 +1000
Subject: alpm_dep_from_string: free memory on error

Signed-off-by: Allan McRae <allan@archlinux.org>
---
 lib/libalpm/deps.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

(limited to 'lib')

diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c
index b12c6293..d105a324 100644
--- a/lib/libalpm/deps.c
+++ b/lib/libalpm/deps.c
@@ -473,7 +473,7 @@ alpm_depend_t SYMEXPORT *alpm_dep_from_string(const char *depstring)
 
 	/* Note the extra space in ": " to avoid matching the epoch */
 	if((desc = strstr(depstring, ": ")) != NULL) {
-		STRDUP(depend->desc, desc + 2, return NULL);
+		STRDUP(depend->desc, desc + 2, goto error);
 		deplen = desc - depstring;
 	} else {
 		/* no description- point desc at NULL at end of string for later use */
@@ -513,13 +513,17 @@ alpm_depend_t SYMEXPORT *alpm_dep_from_string(const char *depstring)
 	}
 
 	/* copy the right parts to the right places */
-	STRNDUP(depend->name, depstring, ptr - depstring, return NULL);
+	STRNDUP(depend->name, depstring, ptr - depstring, goto error);
 	depend->name_hash = _alpm_hash_sdbm(depend->name);
 	if(version) {
-		STRNDUP(depend->version, version, desc - version, return NULL);
+		STRNDUP(depend->version, version, desc - version, goto error);
 	}
 
 	return depend;
+
+error:
+	alpm_dep_free(depend);
+	return NULL;
 }
 
 alpm_depend_t *_alpm_dep_dup(const alpm_depend_t *dep)
-- 
cgit v1.2.3-70-g09d2