summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2013-08-18 01:20:32 +0000
committerChandler Carruth <chandlerc@gmail.com>2013-08-18 01:20:32 +0000
commit67ff8b7185fc47267f1d1eaeaf5520a62939180d (patch)
tree18146492154e28f1ad656b0754d07b05761b5958 /llvm/lib/Support
parent3f5279cc2646cafdce99f7e2f769d04845585369 (diff)
downloadbcm5719-llvm-67ff8b7185fc47267f1d1eaeaf5520a62939180d.tar.gz
bcm5719-llvm-67ff8b7185fc47267f1d1eaeaf5520a62939180d.zip
Go through the really awkward dance required to delete the memory
allocated by setupterm. Without this, some folks are seeing leaked memory whenever this routine is called more than once. Thanks to Craig Topper for the report. llvm-svn: 188615
Diffstat (limited to 'llvm/lib/Support')
-rw-r--r--llvm/lib/Support/Unix/Process.inc14
1 files changed, 12 insertions, 2 deletions
diff --git a/llvm/lib/Support/Unix/Process.inc b/llvm/lib/Support/Unix/Process.inc
index 538f05f980d..8bc8d91eb54 100644
--- a/llvm/lib/Support/Unix/Process.inc
+++ b/llvm/lib/Support/Unix/Process.inc
@@ -240,10 +240,12 @@ unsigned Process::StandardErrColumns() {
}
#ifdef HAVE_TERMINFO
-// We manually declare these two extern functions because finding the correct
+// We manually declare these extern functions because finding the correct
// headers from various terminfo, curses, or other sources is harder than
// writing their specs down.
extern "C" int setupterm(char *term, int filedes, int *errret);
+extern "C" struct term *set_curterm(struct term *termp);
+extern "C" int del_curterm(struct term *termp);
extern "C" int tigetnum(char *capname);
#endif
@@ -272,7 +274,15 @@ static bool terminalHasColors(int fd) {
//
// The 'tigetnum' routine returns -2 or -1 on errors, and might return 0 if
// the terminfo says that no colors are supported.
- if (tigetnum(const_cast<char *>("colors")) > 0)
+ bool HasColors = tigetnum(const_cast<char *>("colors")) > 0;
+
+ // Now extract the structure allocated by setupterm and free its memory
+ // through a really silly dance.
+ struct term *termp = set_curterm((struct term *)0);
+ (void)del_curterm(termp); // Drop any errors here.
+
+ // Return true if we found a color capabilities for the current terminal.
+ if (HasColors)
return true;
#endif
OpenPOWER on IntegriCloud