Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 4 Jun 2020 16:24:13 +0000 (UTC)
From:      Mark Johnston <markj@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r361793 - head/sbin/dhclient
Message-ID:  <202006041624.054GODUi011668@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: markj
Date: Thu Jun  4 16:24:13 2020
New Revision: 361793
URL: https://svnweb.freebsd.org/changeset/base/361793

Log:
  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

Modified:
  head/sbin/dhclient/dispatch.c

Modified: head/sbin/dhclient/dispatch.c
==============================================================================
--- head/sbin/dhclient/dispatch.c	Thu Jun  4 16:05:24 2020	(r361792)
+++ head/sbin/dhclient/dispatch.c	Thu Jun  4 16:24:13 2020	(r361793)
@@ -474,13 +474,16 @@ add_protocol(const char *name, int fd, void (*handler)
 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;
 		}
 	}
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202006041624.054GODUi011668>