From ed95d86d82a3ea4cf95906e500873a1cb3f91e4e Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Thu, 26 Apr 2007 19:18:57 +0000 Subject: [PATCH] Avoid segfault when ticky file argument is stderr If you compiled a program with -ticky and ran it with: ./foo +RTS -rstderr -RTS the result would be a segfault. This was because the RTS interprets stderr to mean "use debugBelch to print out messages," and sets the ticky file pointer to NULL as a result, but PrintTickyInfo (the function in Ticky.c that prints out the ticky report) wasn't checking for NULL. I changed PrintTickyInfo to check whether the ticky file pointer is NULL and output to stderr if so. Also removed an unused import from CodeOutput.lhs. --- compiler/main/CodeOutput.lhs | 2 -- rts/Ticky.c | 8 ++++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/compiler/main/CodeOutput.lhs b/compiler/main/CodeOutput.lhs index 61b10bc..0e52077 100644 --- a/compiler/main/CodeOutput.lhs +++ b/compiler/main/CodeOutput.lhs @@ -30,8 +30,6 @@ import Cmm ( Cmm ) import HscTypes import DynFlags -import StaticFlags ( opt_DoTickyProfiling ) - import ErrUtils ( dumpIfSet_dyn, showPass, ghcExit ) import Outputable import Pretty ( Mode(..), printDoc ) diff --git a/rts/Ticky.c b/rts/Ticky.c index 8901331..2cd3740 100644 --- a/rts/Ticky.c +++ b/rts/Ticky.c @@ -110,6 +110,14 @@ PrintTickyInfo(void) FILE *tf = RtsFlags.TickyFlags.tickyFile; + /* If tf = NULL, that means the user passed in stderr for the ticky stats + file. According to a comment in RtsFlags.c, this means to use + debugBelch to print out messages. But this function prints out a lot + of stuff so in order to avoid changing a lot of code, we just dump + the same output to stderr (for now). */ + if( tf == NULL ) + tf = stderr; + /* krc: avoid dealing with this just now */ #if FALSE fprintf(tf,"\n\nALLOCATIONS: %ld (%ld words total: %ld admin, %ld goods, %ld slop)\n", -- 1.7.10.4