From: Todd C. Miller Date: Thu, 17 Jan 2002 15:35:54 +0000 (+0000) Subject: Don't use memory after it has been freed. X-Git-Tag: SUDO_1_6_6~34 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1b6bfbf452b2567ba55aa2395e649a8e6f40e0f9;p=sudo Don't use memory after it has been freed. --- diff --git a/visudo.c b/visudo.c index e26df1cd2..1755bd58e 100644 --- a/visudo.c +++ b/visudo.c @@ -277,7 +277,7 @@ main(argc, argv) * See if we can use the user's choice of editors either because * we allow any $EDITOR or because $EDITOR is in the allowable list. */ - Editor = NULL; + Editor = EditorPath = NULL; if (def_flag(I_ENV_EDITOR) && UserEditor) Editor = UserEditor; else if (UserEditor) { @@ -318,7 +318,6 @@ main(argc, argv) break; } } while ((Editor = strtok(NULL, ":"))); - free(EditorPath); } /* @@ -326,6 +325,8 @@ main(argc, argv) * find one that exists, is regular, and is executable. */ if (Editor == NULL || *Editor == '\0') { + if (EditorPath != NULL) + free(EditorPath); EditorPath = estrdup(def_str(I_EDITOR)); Editor = strtok(EditorPath, ":"); do {