Skip to content

Commit e1c1a32

Browse files
peffgitster
authored andcommitted
Revert "prompt: clean up strbuf usage"
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d2446df commit e1c1a32

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

prompt.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ static char *do_askpass(const char *cmd, const char *prompt)
2222
if (start_command(&pass))
2323
return NULL;
2424

25+
strbuf_reset(&buffer);
2526
if (strbuf_read(&buffer, pass.out, 20) < 0)
2627
err = 1;
2728

@@ -38,7 +39,7 @@ static char *do_askpass(const char *cmd, const char *prompt)
3839

3940
strbuf_setlen(&buffer, strcspn(buffer.buf, "\r\n"));
4041

41-
return strbuf_detach(&buffer, NULL);
42+
return buffer.buf;
4243
}
4344

4445
char *git_prompt(const char *prompt, int flags)

0 commit comments

Comments
 (0)