[pacman-dev,3/7] plug memory leaks in _alpm_key_import

Message ID 20210116072101.38203-3-andrew.gregory.8@gmail.com
State Accepted, archived
Headers show
Series [pacman-dev,1/7] pacman: indicate --overwrite takes a glob | expand

Commit Message

Andrew Gregory Jan. 16, 2021, 7:20 a.m. UTC
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
---
 lib/libalpm/signing.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Patch

diff --git a/lib/libalpm/signing.c b/lib/libalpm/signing.c
index 2cbbd103..1f6977a0 100644
--- a/lib/libalpm/signing.c
+++ b/lib/libalpm/signing.c
@@ -505,7 +505,7 @@  int _alpm_key_import(alpm_handle_t *handle, const char *uid, const char *fpr)
 	}
 
 	STRDUP(fetch_key.uid, uid, return -1);
-	STRDUP(fetch_key.fingerprint, fpr, return -1);
+	STRDUP(fetch_key.fingerprint, fpr, free(fetch_key.uid); return -1);
 
 	alpm_question_import_key_t question = {
 				.type = ALPM_QUESTION_IMPORT_KEY,
@@ -517,6 +517,7 @@  int _alpm_key_import(alpm_handle_t *handle, const char *uid, const char *fpr)
 		/* Try to import the key from a WKD first */
 		if(email_from_uid(uid, &email) == 0) {
 			ret = key_import_wkd(handle, email);
+			free(email);
 		}
 
 		/* If importing from the WKD fails, fall back to keyserver lookup */
@@ -537,6 +538,8 @@  int _alpm_key_import(alpm_handle_t *handle, const char *uid, const char *fpr)
 		}
 	}
 	gpgme_key_unref(fetch_key.data);
+	free(fetch_key.uid);
+	free(fetch_key.fingerprint);
 
 	return ret;
 }