[commit: ghc] master: rts: Fix parsing of profiler selectors (535896e)

git at git.haskell.org git at git.haskell.org
Thu Apr 7 13:24:36 UTC 2016


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/535896e58f7fc8d89a5ff34629a3471eac529d93/ghc

>---------------------------------------------------------------

commit 535896e58f7fc8d89a5ff34629a3471eac529d93
Author: Ben Gamari <bgamari.foss at gmail.com>
Date:   Thu Apr 7 15:26:11 2016 +0200

    rts: Fix parsing of profiler selectors
    
    69822f0c5b67161b4d7558081bc94f6f3a7c5dbb broke this as it held on to a
    reference into the `arg` string, which is later freed. Humbug.
    
    Test Plan: Try using filtering
    
    Reviewers: austin
    
    Subscribers: thomie
    
    Differential Revision: https://phabricator.haskell.org/D2090
    
    GHC Trac Issues: #11810


>---------------------------------------------------------------

535896e58f7fc8d89a5ff34629a3471eac529d93
 rts/RtsFlags.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/rts/RtsFlags.c b/rts/RtsFlags.c
index 3387355..7f0821a 100644
--- a/rts/RtsFlags.c
+++ b/rts/RtsFlags.c
@@ -1566,7 +1566,7 @@ static rtsBool read_heap_profiling_flag(const char *arg_in)
     // However, for sanity we want to guarantee const-correctness and parsing
     // really ought to be an immutable operation. To avoid rewriting the parser
     // we just operate on a temporary copy of the argument.
-    char *arg = strdup(arg_in);
+    const char *arg = strdup(arg_in);
     rtsBool error = rtsFalse;
     switch (arg[2]) {
     case '\0':
@@ -1597,35 +1597,37 @@ static rtsBool read_heap_profiling_flag(const char *arg_in)
                 if (!right)
                     right = arg + strlen(arg);
 
-                *right = '\0';
+                char *selector = strndup(left, right - left);
 
                 switch (arg[2]) {
                 case 'c': // cost centre label select
-                    RtsFlags.ProfFlags.ccSelector = left;
+                    RtsFlags.ProfFlags.ccSelector = selector;
                     break;
                 case 'C':
-                    RtsFlags.ProfFlags.ccsSelector = left;
+                    RtsFlags.ProfFlags.ccsSelector = selector;
                     break;
                 case 'M':
                 case 'm': // cost centre module select
-                    RtsFlags.ProfFlags.modSelector = left;
+                    RtsFlags.ProfFlags.modSelector = selector;
                     break;
                 case 'D':
                 case 'd': // closure descr select
-                    RtsFlags.ProfFlags.descrSelector = left;
+                    RtsFlags.ProfFlags.descrSelector = selector;
                     break;
                 case 'Y':
                 case 'y': // closure type select
-                    RtsFlags.ProfFlags.typeSelector = left;
+                    RtsFlags.ProfFlags.typeSelector = selector;
                     break;
                 case 'R':
                 case 'r': // retainer select
-                    RtsFlags.ProfFlags.retainerSelector = left;
+                    RtsFlags.ProfFlags.retainerSelector = selector;
                     break;
                 case 'B':
                 case 'b': // biography select
-                    RtsFlags.ProfFlags.bioSelector = left;
+                    RtsFlags.ProfFlags.bioSelector = selector;
                     break;
+                default:
+                    free(selector);
                 }
             }
             break;



More information about the ghc-commits mailing list