From: Stefan Baranoff Date: Tue, 19 May 2020 00:57:14 +0000 (+0000) Subject: Fix memory leak from passphrase callback X-Git-Tag: v3.4.3~1^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F1378%2Fhead;p=thirdparty%2Flibarchive.git 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. --- 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 *