From c47f5f7abd68bb6e03737aaca20de23533639cc4 Mon Sep 17 00:00:00 2001
From: "Todd C. Miller" <Todd.Miller@courtesan.com>
Date: Tue, 5 Mar 2013 10:16:50 -0500
Subject: [PATCH] Fix potential double free in an error path.

---
 plugins/sudoers/toke.c | 5 +++--
 plugins/sudoers/toke.l | 5 +++--
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/plugins/sudoers/toke.c b/plugins/sudoers/toke.c
index dc60f8ff0..743d5ef94 100644
--- a/plugins/sudoers/toke.c
+++ b/plugins/sudoers/toke.c
@@ -3436,6 +3436,7 @@ switch_dir(struct include_stack *stack, char *dirpath)
 	pl->path = path;
 	pl->next = first;
 	first = pl;
+	path = NULL;
 	count++;
     }
     closedir(dir);
@@ -3477,8 +3478,8 @@ bad:
     while (first != NULL) {
 	pl = first;
 	first = pl->next;
-	free(pl->path);
-	free(pl);
+	efree(pl->path);
+	efree(pl);
     }
     efree(sorted);
     efree(dirpath);
diff --git a/plugins/sudoers/toke.l b/plugins/sudoers/toke.l
index 6a9bae471..012d3780a 100644
--- a/plugins/sudoers/toke.l
+++ b/plugins/sudoers/toke.l
@@ -714,6 +714,7 @@ switch_dir(struct include_stack *stack, char *dirpath)
 	pl->path = path;
 	pl->next = first;
 	first = pl;
+	path = NULL;
 	count++;
     }
     closedir(dir);
@@ -755,8 +756,8 @@ bad:
     while (first != NULL) {
 	pl = first;
 	first = pl->next;
-	free(pl->path);
-	free(pl);
+	efree(pl->path);
+	efree(pl);
     }
     efree(sorted);
     efree(dirpath);
-- 
2.40.0