[commit: ghc] ghc-8.0: rts: Fix parsing of profiler selectors (8735569)

git at git.haskell.org git at git.haskell.org
Sun Apr 10 13:39:46 UTC 2016


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

On branch  : ghc-8.0
Link       : http://ghc.haskell.org/trac/ghc/changeset/8735569d17902283d696251d59d76f10a5703351/ghc

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

commit 8735569d17902283d696251d59d76f10a5703351
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
    
    (cherry picked from commit 535896e58f7fc8d89a5ff34629a3471eac529d93)


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

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

diff --git a/rts/RtsFlags.c b/rts/RtsFlags.c
index b497429..ed6f43e 100644
--- a/rts/RtsFlags.c
+++ b/rts/RtsFlags.c
@@ -1576,7 +1576,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':
@@ -1607,35 +1607,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