[Xorp-hackers] PATCH: Small memory leak in CliCommand

Ben Greear greearb at candelatech.com
Thu Oct 29 10:57:18 PDT 2009


Found this while using valgrind.  I think the patch will work, but I haven't
actually tested it yet.

==27835== 6,184 (240 direct, 5,944 indirect) bytes in 1 blocks are definitely lost in loss record 48 of 59
==27835==    at 0x4A06FFC: operator new(unsigned long) (vg_replace_malloc.c:230)
==27835==    by 0x53D5DD: CliCommand::add_pipes(std::string&) (cli_command.cc:426)
==27835==    by 0x5215C3: CliNode::CliNode(int, xorp_module_id, EventLoop&) (cli_node.cc:94)
==27835==    by 0x40714F: XrlFeaNode::XrlFeaNode(EventLoop&, std::string const&, std::string const&, std::string const&, unsigned shor
t, bool) (xrl_fea_node.cc:79)
==27835==    by 0x40638C: fea_main(std::string const&, unsigned short) (xorp_fea.cc:97)
==27835==    by 0x406681: main (xorp_fea.cc:181)
==27835==


[greearb at ben-dt2 xorp.ct]$ git diff
diff --git a/cli/cli_command.cc b/cli/cli_command.cc
index 99a003b..256157f 100644
--- a/cli/cli_command.cc
+++ b/cli/cli_command.cc
@@ -95,6 +95,7 @@ CliCommand::~CliCommand()
  {
      // Delete recursively all child commands
      delete_pointers_list(_child_command_list);
+    delete_pipes();
  }

  //
@@ -428,6 +429,7 @@ CliCommand::add_pipes(string& error_msg)
      if (com0 == NULL) {
         return (XORP_ERROR);
      }
+    delete_pipes(); // be sure to not leak memory if one is already set.
      set_cli_command_pipe(com0);

      cli_pipe = new CliPipe("count");


-- 
Ben Greear <greearb at candelatech.com>
Candela Technologies Inc  http://www.candelatech.com



More information about the Xorp-hackers mailing list