]> Pileus Git - ~andy/git/commitdiff
Revert "prompt: clean up strbuf usage"
authorJeff King <peff@peff.net>
Thu, 2 Jan 2014 03:03:30 +0000 (22:03 -0500)
committerJunio C Hamano <gitster@pobox.com>
Thu, 2 Jan 2014 18:21:40 +0000 (10:21 -0800)
This reverts commit 31b49d9b653803e7c7fd18b21c8bdd86e3421668.

That commit taught do_askpass to hand ownership of our
buffer back to the caller rather than simply return a
pointer into our internal strbuf.  What it failed to notice,
though, was that our internal strbuf is static, because we
are trying to emulate the getpass() interface.

By handing off ownership, we created a memory leak that
cannot be solved. Sometimes git_prompt returns a static
buffer from getpass() (or our smarter git_terminal_prompt
wrapper), and sometimes it returns an allocated string from
do_askpass.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
prompt.c

index d851807feb9849813635471d7099e67ed743a2d7..d7bb17cb663c2f47ad59d34ecea17c6cc977e815 100644 (file)
--- a/prompt.c
+++ b/prompt.c
@@ -22,6 +22,7 @@ static char *do_askpass(const char *cmd, const char *prompt)
        if (start_command(&pass))
                return NULL;
 
+       strbuf_reset(&buffer);
        if (strbuf_read(&buffer, pass.out, 20) < 0)
                err = 1;
 
@@ -38,7 +39,7 @@ static char *do_askpass(const char *cmd, const char *prompt)
 
        strbuf_setlen(&buffer, strcspn(buffer.buf, "\r\n"));
 
-       return strbuf_detach(&buffer, NULL);
+       return buffer.buf;
 }
 
 char *git_prompt(const char *prompt, int flags)