]> diplodocus.org Git - nmh/blobdiff - sbr/read_switch_multiword_via_readline.c
path.c: Re-format path() to make it more clear what's happening.
[nmh] / sbr / read_switch_multiword_via_readline.c
index fd6244cd68a8026d3521e9397367ba67c31a38c1..3d6e88184368d2ae79d9b0244122d870c3e6a197 100644 (file)
@@ -1,5 +1,4 @@
-/*
- * read_switch_multiword_via_readline.c -- get an answer from the user, with readline
+/* read_switch_multiword_via_readline.c -- get an answer from the user, with readline
  *
  * This code is Copyright (c) 2012, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -50,6 +49,8 @@ read_switch_multiword_via_readline(char *prompt, struct swit *ansp)
        add_history(ans);
        strncpy(ansbuf, ans, sizeof(ansbuf));
        ansbuf[sizeof(ansbuf) - 1] = '\0';
+        free(ans);
+
        cpp = brkstring(ansbuf, " ", NULL);
        switch (smatch(*cpp, ansp)) {
            case AMBIGSW:
@@ -59,10 +60,8 @@ read_switch_multiword_via_readline(char *prompt, struct swit *ansp)
                printf(" -%s unknown. Hit <CR> for help.\n", *cpp);
                continue;
            default:
-               free(ans);
                return cpp;
        }
-       free(ans);
     }
 }