Skip to content

Commit

Permalink
Revert "prompt: clean up strbuf usage"
Browse files Browse the repository at this point in the history
This reverts commit 31b49d9.

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>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Jan 2, 2014
1 parent d2446df commit e1c1a32
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion prompt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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)
Expand Down

0 comments on commit e1c1a32

Please sign in to comment.