]> granicus.if.org Git - sudo/commitdiff
Don't use memory after it has been freed.
authorTodd C. Miller <Todd.Miller@courtesan.com>
Thu, 17 Jan 2002 15:35:54 +0000 (15:35 +0000)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Thu, 17 Jan 2002 15:35:54 +0000 (15:35 +0000)
visudo.c

index e26df1cd2c0dfd1602407f2f65a8228c8d0ce9b7..1755bd58e378e506f12e03d60be535174f8f411d 100644 (file)
--- 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 {