Commit 535896e5 authored by Ben Gamari's avatar Ben Gamari Committed by Ben Gamari

rts: Fix parsing of profiler selectors

69822f0c 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
parent 6b6bebaf
...@@ -1566,7 +1566,7 @@ static rtsBool read_heap_profiling_flag(const char *arg_in) ...@@ -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 // However, for sanity we want to guarantee const-correctness and parsing
// really ought to be an immutable operation. To avoid rewriting the parser // really ought to be an immutable operation. To avoid rewriting the parser
// we just operate on a temporary copy of the argument. // we just operate on a temporary copy of the argument.
char *arg = strdup(arg_in); const char *arg = strdup(arg_in);
rtsBool error = rtsFalse; rtsBool error = rtsFalse;
switch (arg[2]) { switch (arg[2]) {
case '\0': case '\0':
...@@ -1597,35 +1597,37 @@ static rtsBool read_heap_profiling_flag(const char *arg_in) ...@@ -1597,35 +1597,37 @@ static rtsBool read_heap_profiling_flag(const char *arg_in)
if (!right) if (!right)
right = arg + strlen(arg); right = arg + strlen(arg);
*right = '\0'; char *selector = strndup(left, right - left);
switch (arg[2]) { switch (arg[2]) {
case 'c': // cost centre label select case 'c': // cost centre label select
RtsFlags.ProfFlags.ccSelector = left; RtsFlags.ProfFlags.ccSelector = selector;
break; break;
case 'C': case 'C':
RtsFlags.ProfFlags.ccsSelector = left; RtsFlags.ProfFlags.ccsSelector = selector;
break; break;
case 'M': case 'M':
case 'm': // cost centre module select case 'm': // cost centre module select
RtsFlags.ProfFlags.modSelector = left; RtsFlags.ProfFlags.modSelector = selector;
break; break;
case 'D': case 'D':
case 'd': // closure descr select case 'd': // closure descr select
RtsFlags.ProfFlags.descrSelector = left; RtsFlags.ProfFlags.descrSelector = selector;
break; break;
case 'Y': case 'Y':
case 'y': // closure type select case 'y': // closure type select
RtsFlags.ProfFlags.typeSelector = left; RtsFlags.ProfFlags.typeSelector = selector;
break; break;
case 'R': case 'R':
case 'r': // retainer select case 'r': // retainer select
RtsFlags.ProfFlags.retainerSelector = left; RtsFlags.ProfFlags.retainerSelector = selector;
break; break;
case 'B': case 'B':
case 'b': // biography select case 'b': // biography select
RtsFlags.ProfFlags.bioSelector = left; RtsFlags.ProfFlags.bioSelector = selector;
break; break;
default:
free(selector);
} }
} }
break; break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment