|
From: <sv...@va...> - 2007-03-26 23:45:02
|
Author: njn
Date: 2007-03-27 00:45:01 +0100 (Tue, 27 Mar 2007)
New Revision: 6669
Log:
Fix bug 142197: don't free --toolname:foo options after they've been munged,
because tools should be able to assume that they are never freed, just like
other options.
Merged from trunk.
Modified:
branches/VALGRIND_3_2_BRANCH/coregrind/m_main.c
Modified: branches/VALGRIND_3_2_BRANCH/coregrind/m_main.c
===================================================================
--- branches/VALGRIND_3_2_BRANCH/coregrind/m_main.c 2007-03-26 23:38:42 UTC (rev 6668)
+++ branches/VALGRIND_3_2_BRANCH/coregrind/m_main.c 2007-03-26 23:45:01 UTC (rev 6669)
@@ -1074,17 +1074,33 @@
HChar* arg = VG_(args_for_valgrind).strs[i];
HChar* colon = arg;
- /* Look for a colon in the switch name */
+ // Look for a colon in the option name.
while (*colon && *colon != ':' && *colon != '=')
colon++;
- /* Look for matching "--toolname:foo" */
+ // Does it have the form "--toolname:foo"? We have to do it at the start
+ // in case someone has combined a prefix with a core-specific option,
+ // eg. "--memcheck:verbose".
if (*colon == ':') {
if (VG_CLO_STREQN(2, arg, "--") &&
VG_CLO_STREQN(toolname_len, arg+2, toolname) &&
VG_CLO_STREQN(1, arg+2+toolname_len, ":"))
{
- // prefix matches, convert "--toolname:foo" to "--foo"
+ // Prefix matches, convert "--toolname:foo" to "--foo".
+ // Two things to note:
+ // - We cannot modify the option in-place. If we did, and then
+ // a child was spawned with --trace-children=yes, the
+ // now-non-prefixed option would be passed and could screw up
+ // the child.
+ // - We create copies, and never free them. Why? Non-prefixed
+ // options hang around forever, so tools need not make copies
+ // of strings within them. We need to have the same behaviour
+ // for prefixed options. The pointer to the copy will be lost
+ // once we leave this function (although a tool may keep a
+ // pointer into it), but the space wasted is insignificant.
+ // (In bug #142197, the copies were being freed, which caused
+ // problems for tools that reasonably assumed that arguments
+ // wouldn't disappear on them.)
if (0)
VG_(printf)("tool-specific arg: %s\n", arg);
arg = VG_(strdup)(arg + toolname_len + 1);
@@ -1098,11 +1114,11 @@
}
/* Ignore these options - they've already been handled */
- if (VG_CLO_STREQN( 7, arg, "--tool=")) goto skip_arg;
- if (VG_CLO_STREQN(20, arg, "--command-line-only=")) goto skip_arg;
+ if (VG_CLO_STREQN( 7, arg, "--tool=")) { }
+ else if (VG_CLO_STREQN(20, arg, "--command-line-only=")) { }
+ else if (VG_CLO_STREQ(arg, "--")) { }
+ else if (VG_CLO_STREQ(arg, "-d")) { }
- if ( VG_CLO_STREQ(arg, "--")) goto skip_arg;
-
else if (VG_CLO_STREQ(arg, "-v") ||
VG_CLO_STREQ(arg, "--verbose"))
VG_(clo_verbosity)++;
@@ -1111,10 +1127,6 @@
VG_CLO_STREQ(arg, "--quiet"))
VG_(clo_verbosity)--;
- else if (VG_CLO_STREQ(arg, "-d")) {
- /* do nothing */
- }
-
else VG_BOOL_CLO(arg, "--xml", VG_(clo_xml))
else VG_BOOL_CLO(arg, "--db-attach", VG_(clo_db_attach))
else VG_BOOL_CLO(arg, "--demangle", VG_(clo_demangle))
@@ -1263,10 +1275,6 @@
|| ! VG_TDICT_CALL(tool_process_cmd_line_option, arg) ) {
VG_(bad_option)(arg);
}
- skip_arg:
- if (arg != VG_(args_for_valgrind).strs[i]) {
- VG_(free)(arg);
- }
}
/* Make VEX control parameters sane */
|