dhclient: Fix a logic bug remove_protocol().

A logic bug in remove_protocol() meant that it would remove (leak) all
structures in the list preceding the one intended for removal.

PR:		245971
Submitted by:	joost@jodocus.org (original version)
MFC after:	1 week
This commit is contained in:
Mark Johnston 2020-06-04 16:24:13 +00:00
parent e9ee2675cb
commit 0006082054
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=361793

View File

@ -474,13 +474,16 @@ add_protocol(const char *name, int fd, void (*handler)(struct protocol *),
void
remove_protocol(struct protocol *proto)
{
struct protocol *p, *next;
struct protocol *p, *prev;
for (p = protocols; p; p = next) {
next = p->next;
for (p = protocols, prev = NULL; p != NULL; prev = p, p = p->next) {
if (p == proto) {
protocols = p->next;
if (prev == NULL)
protocols = p->next;
else
prev->next = p->next;
free(p);
break;
}
}
}