From 35997ddf613702cfef0b026c6a4987dd68918897 Mon Sep 17 00:00:00 2001 From: Stefan Baranoff Date: Tue, 19 May 2020 00:57:14 +0000 Subject: [PATCH] Fix memory leak from passphrase callback There is a bug in the linked list implementation for passphrases. The insert to head function does not account for the tail==head case and causes a leak. The first entry into the list is lost when the second entry is added. The second and beyond entries are are released properly, but the first is lost entirely. --- libarchive/archive_read_add_passphrase.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libarchive/archive_read_add_passphrase.c b/libarchive/archive_read_add_passphrase.c index cf821b5d4..f0b1ab933 100644 --- a/libarchive/archive_read_add_passphrase.c +++ b/libarchive/archive_read_add_passphrase.c @@ -57,6 +57,10 @@ insert_passphrase_to_head(struct archive_read *a, { p->next = a->passphrases.first; a->passphrases.first = p; + if (&a->passphrases.first == a->passphrases.last) { + a->passphrases.last = &p->next; + p->next = NULL; + } } static struct archive_read_passphrase * -- 2.47.2