summaryrefslogtreecommitdiff
path: root/compat/winansi.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2017-05-29 03:34:44 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-05-29 03:34:44 (GMT)
commit849e671b52e11d4a2f70d577dd2c806f3ca756fe (patch)
treef564d4d2782856efcdcff278b385a989c031a6c1 /compat/winansi.c
parent137a2613a07e556fd77fe374c6f4edd2d5e1b1fc (diff)
parent443a12f37be1c5967785b83bf04935fe357afb9b (diff)
downloadgit-849e671b52e11d4a2f70d577dd2c806f3ca756fe.zip
git-849e671b52e11d4a2f70d577dd2c806f3ca756fe.tar.gz
git-849e671b52e11d4a2f70d577dd2c806f3ca756fe.tar.bz2
Merge branch 'js/plug-leaks'
Fix memory leaks pointed out by Coverity (and people). * js/plug-leaks: (26 commits) checkout: fix memory leak submodule_uses_worktrees(): plug memory leak show_worktree(): plug memory leak name-rev: avoid leaking memory in the `deref` case remote: plug memory leak in match_explicit() add_reflog_for_walk: avoid memory leak shallow: avoid memory leak line-log: avoid memory leak receive-pack: plug memory leak in update() fast-export: avoid leaking memory in handle_tag() mktree: plug memory leaks reported by Coverity pack-redundant: plug memory leak setup_discovered_git_dir(): plug memory leak setup_bare_git_dir(): help static analysis split_commit_in_progress(): simplify & fix memory leak checkout: fix memory leak cat-file: fix memory leak mailinfo & mailsplit: check for EOF while parsing status: close file descriptor after reading git-rebase-todo difftool: address a couple of resource/memory leaks ...
Diffstat (limited to 'compat/winansi.c')
-rw-r--r--compat/winansi.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/compat/winansi.c b/compat/winansi.c
index 793420f..a11a0f1 100644
--- a/compat/winansi.c
+++ b/compat/winansi.c
@@ -105,6 +105,13 @@ static int is_console(int fd)
if (!fd) {
if (!GetConsoleMode(hcon, &mode))
return 0;
+ /*
+ * This code path is only reached if there is no console
+ * attached to stdout/stderr, i.e. we will not need to output
+ * any text to any console, therefore we might just as well
+ * use black as foreground color.
+ */
+ sbi.wAttributes = 0;
} else if (!GetConsoleScreenBufferInfo(hcon, &sbi))
return 0;
@@ -133,6 +140,11 @@ static void write_console(unsigned char *str, size_t len)
/* convert utf-8 to utf-16 */
int wlen = xutftowcsn(wbuf, (char*) str, ARRAY_SIZE(wbuf), len);
+ if (wlen < 0) {
+ wchar_t *err = L"[invalid]";
+ WriteConsoleW(console, err, wcslen(err), &dummy, NULL);
+ return;
+ }
/* write directly to console */
WriteConsoleW(console, wbuf, wlen, &dummy, NULL);