Ben Greear <[EMAIL PROTECTED]> wrote:
> Ok, the CLI code is harder to fix that I thought it would be!
>
> It seems that when you type 'exit', the
>
> RouterCLI::logout_func()
>
> is called, which then calls _cli_node.delete_client
>
> But, that client that it's deleting originally called the method,
> so we end up referencing stale memory when we return back up the
> call-stack. Here's the stack reported
> by valgrind. The line numbers might be slightly off due to debugging
> code I added.
Please apply the patch below and see whether it solves the stale
memory problem and/or some of the earlier problems.
Thanks,
Pavlin
Index: cli/cli_node.cc
===================================================================
RCS file: /usr/local/share/doc/apache/cvs/xorp/cli/cli_node.cc,v
retrieving revision 1.38
diff -u -p -r1.38 cli_node.cc
--- cli/cli_node.cc 12 Oct 2007 07:53:44 -0000 1.38
+++ cli/cli_node.cc 12 Oct 2007 23:11:08 -0000
@@ -621,18 +621,16 @@ CliNode::add_client(XorpFd input_fd, Xor
}
int
-CliNode::delete_client(CliClient *cli_client, string& error_msg)
+CliNode::remove_client(CliClient *cli_client, string& error_msg)
{
if (delete_connection(cli_client, error_msg) != XORP_OK)
return (XORP_ERROR);
- // XXX: delete the client itself if it is still around
+ // XXX: Remove the client itself if it is still around
list<CliClient *>::iterator iter;
-
iter = find(_client_list.begin(), _client_list.end(), cli_client);
if (iter != _client_list.end()) {
_client_list.erase(iter);
- delete cli_client;
}
return (XORP_OK);
Index: cli/cli_node.hh
===================================================================
RCS file: /usr/local/share/doc/apache/cvs/xorp/cli/cli_node.hh,v
retrieving revision 1.30
diff -u -p -r1.30 cli_node.hh
--- cli/cli_node.hh 19 May 2007 01:52:39 -0000 1.30
+++ cli/cli_node.hh 12 Oct 2007 23:11:08 -0000
@@ -351,13 +351,15 @@ public:
const string& startup_cli_prompt, string& error_msg);
/**
- * Delete a CLI client (@ref CliClient) from the CLI.
+ * Remove a CLI client (@ref CliClient) from the CLI.
*
- * @param cli_client the CLI client (@ref CliClient) to delete.
+ * Note that the CLI client object itself is not deleted.
+ *
+ * @param cli_client the CLI client (@ref CliClient) to remove.
* @param error_msg the error message (if error).
* @return XORP_OK on success, otherwise XORP_ERROR.
*/
- int delete_client(CliClient *cli_client, string& error_msg);
+ int remove_client(CliClient *cli_client, string& error_msg);
typedef XorpCallback1<void,
CliClient* // CLI client to delete
Index: rtrmgr/cli.cc
===================================================================
RCS file: /usr/local/share/doc/apache/cvs/xorp/rtrmgr/cli.cc,v
retrieving revision 1.137
diff -u -p -r1.137 cli.cc
--- rtrmgr/cli.cc 16 Feb 2007 22:47:20 -0000 1.137
+++ rtrmgr/cli.cc 12 Oct 2007 23:11:16 -0000
@@ -99,6 +99,7 @@ RouterCLI::RouterCLI(XorpShellBase& xorp
: _xorpsh(xorpsh),
_cli_node(cli_node),
_cli_client_ptr(NULL),
+ _removed_cli_client_ptr(NULL),
_verbose(verbose),
_operational_mode_prompt(DEFAULT_XORP_PROMPT_OPERATIONAL),
_configuration_mode_prompt(DEFAULT_XORP_PROMPT_CONFIGURATION),
@@ -558,6 +559,10 @@ RouterCLI::~RouterCLI()
delete _cli_client_ptr;
_cli_client_ptr = NULL;
}
+ if (_removed_cli_client_ptr != NULL) {
+ delete _removed_cli_client_ptr;
+ _removed_cli_client_ptr = NULL;
+ }
}
bool
@@ -1875,11 +1880,15 @@ RouterCLI::logout_func(const string& ,
}
idle_ui();
- if (_cli_node.delete_client(_cli_client_ptr, error_msg) != XORP_OK) {
+ if (_cli_node.remove_client(_cli_client_ptr, error_msg) != XORP_OK) {
XLOG_FATAL("internal error deleting CLI client: %s",
error_msg.c_str());
return (XORP_ERROR);
}
+
+ // Save the pointer to the removed client so it can be deleted later
+ XLOG_ASSERT(_removed_cli_client_ptr == NULL);
+ _removed_cli_client_ptr = _cli_client_ptr;
_cli_client_ptr = NULL;
return (XORP_OK);
Index: rtrmgr/cli.hh
===================================================================
RCS file: /usr/local/share/doc/apache/cvs/xorp/rtrmgr/cli.hh,v
retrieving revision 1.51
diff -u -p -r1.51 cli.hh
--- rtrmgr/cli.hh 16 Feb 2007 22:47:21 -0000 1.51
+++ rtrmgr/cli.hh 12 Oct 2007 23:11:16 -0000
@@ -257,6 +257,7 @@ private:
CliNode& _cli_node;
CliClient* _cli_client_ptr;
+ CliClient* _removed_cli_client_ptr;
bool _verbose; // Set to true if output is verbose
string _operational_mode_prompt;
string _configuration_mode_prompt;
_______________________________________________
Xorp-hackers mailing list
[email protected]
http://mailman.ICSI.Berkeley.EDU/mailman/listinfo/xorp-hackers