[Lldb-commits] [lldb] r116345 - in /lldb/trunk: scripts/Python/append-debugger-id.py source/Breakpoint/BreakpointIDList.cpp source/Interpreter/CommandInterpreter.cpp tools/driver/Driver.cpp

Caroline Tice ctice at apple.com
Tue Oct 12 14:57:09 PDT 2010


Author: ctice
Date: Tue Oct 12 16:57:09 2010
New Revision: 116345

URL: http://llvm.org/viewvc/llvm-project?rev=116345&view=rev
Log:
Fix some memory leaks.

Add call to lldb.SBDebugger.Initialize() to lldb.py, so it automatically gets called when
the lldb Python module gets loaded.


Modified:
    lldb/trunk/scripts/Python/append-debugger-id.py
    lldb/trunk/source/Breakpoint/BreakpointIDList.cpp
    lldb/trunk/source/Interpreter/CommandInterpreter.cpp
    lldb/trunk/tools/driver/Driver.cpp

Modified: lldb/trunk/scripts/Python/append-debugger-id.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/append-debugger-id.py?rev=116345&r1=116344&r2=116345&view=diff
==============================================================================
--- lldb/trunk/scripts/Python/append-debugger-id.py (original)
+++ lldb/trunk/scripts/Python/append-debugger-id.py Tue Oct 12 16:57:09 2010
@@ -21,6 +21,7 @@
     print "Error:  Unable to open file for appending: " + output_name
 else:
     f_out.write ("debugger_unique_id = 0\n");
+    f_out.write ("lldb.SBDebugger.Initialize()\n");
     try:
         f_out.close()
     except IOError:

Modified: lldb/trunk/source/Breakpoint/BreakpointIDList.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Breakpoint/BreakpointIDList.cpp?rev=116345&r1=116344&r2=116345&view=diff
==============================================================================
--- lldb/trunk/source/Breakpoint/BreakpointIDList.cpp (original)
+++ lldb/trunk/source/Breakpoint/BreakpointIDList.cpp Tue Oct 12 16:57:09 2010
@@ -181,7 +181,6 @@
         if (BreakpointIDList::StringContainsIDRangeExpression (current_arg, &range_start_len, &range_end_pos))
         {
             is_range = true;
-            range_start = (char *) malloc (range_start_len + 1);
             range_start.assign (current_arg, range_start_len);
             range_end = current_arg + range_end_pos;
         }

Modified: lldb/trunk/source/Interpreter/CommandInterpreter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandInterpreter.cpp?rev=116345&r1=116344&r2=116345&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CommandInterpreter.cpp (original)
+++ lldb/trunk/source/Interpreter/CommandInterpreter.cpp Tue Oct 12 16:57:09 2010
@@ -8,6 +8,7 @@
 //===----------------------------------------------------------------------===//
 
 #include <string>
+#include <vector>
 
 #include <getopt.h>
 #include <stdlib.h>
@@ -947,13 +948,10 @@
 }
 
 void
-CommandInterpreter::BuildAliasCommandArgs
-(
-    CommandObject *alias_cmd_obj,
-    const char *alias_name,
-    Args &cmd_args,
-    CommandReturnObject &result
-)
+CommandInterpreter::BuildAliasCommandArgs (CommandObject *alias_cmd_obj,
+                                           const char *alias_name,
+                                           Args &cmd_args,
+                                           CommandReturnObject &result)
 {
     OptionArgVectorSP option_arg_vector_sp = GetAliasOptions (alias_name);
 
@@ -970,10 +968,9 @@
 
         OptionArgVector *option_arg_vector = option_arg_vector_sp.get();
         int old_size = cmd_args.GetArgumentCount();
-        int *used = (int *) malloc ((old_size + 1) * sizeof (int));
-
-        memset (used, 0, (old_size + 1) * sizeof (int));
-        used[0] = 1;
+        std::vector<bool> used (old_size + 1, false);
+        
+        used[0] = true;
 
         for (int i = 0; i < option_arg_vector->size(); ++i)
         {
@@ -1002,7 +999,7 @@
                     else
                     {
                         new_args.AppendArgument (cmd_args.GetArgumentAtIndex (index));
-                        used[index] = 1;
+                        used[index] = true;
                     }
                 }
             }

Modified: lldb/trunk/tools/driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/driver/Driver.cpp?rev=116345&r1=116344&r2=116345&view=diff
==============================================================================
--- lldb/trunk/tools/driver/Driver.cpp (original)
+++ lldb/trunk/tools/driver/Driver.cpp Tue Oct 12 16:57:09 2010
@@ -332,7 +332,8 @@
 }
 
 void
-BuildGetOptTable (lldb::OptionDefinition *expanded_option_table, struct option **getopt_table, uint32_t num_options)
+BuildGetOptTable (lldb::OptionDefinition *expanded_option_table, std::vector<struct option> &getopt_table, 
+                  uint32_t num_options)
 {
     if (num_options == 0)
         return;
@@ -341,25 +342,27 @@
     uint32_t j;
     std::bitset<256> option_seen;
 
+    getopt_table.resize (num_options + 1);
+
     for (i = 0, j = 0; i < num_options; ++i)
     {
         char short_opt = expanded_option_table[i].short_option;
         
         if (option_seen.test(short_opt) == false)
         {
-            (*getopt_table)[j].name    = expanded_option_table[i].long_option;
-            (*getopt_table)[j].has_arg = expanded_option_table[i].option_has_arg;
-            (*getopt_table)[j].flag    = NULL;
-            (*getopt_table)[j].val     = expanded_option_table[i].short_option;
+            getopt_table[j].name    = expanded_option_table[i].long_option;
+            getopt_table[j].has_arg = expanded_option_table[i].option_has_arg;
+            getopt_table[j].flag    = NULL;
+            getopt_table[j].val     = expanded_option_table[i].short_option;
             option_seen.set(short_opt);
             ++j;
         }
     }
 
-    (*getopt_table)[j].name    = NULL;
-    (*getopt_table)[j].has_arg = 0;
-    (*getopt_table)[j].flag    = NULL;
-    (*getopt_table)[j].val     = 0;
+    getopt_table[j].name    = NULL;
+    getopt_table[j].has_arg = 0;
+    getopt_table[j].flag    = NULL;
+    getopt_table[j].val     = 0;
 
 }
 
@@ -456,6 +459,7 @@
     SBError error;
     std::string option_string;
     struct option *long_options = NULL;
+    std::vector<struct option> long_options_vector;
     uint32_t num_options;
 
     for (num_options = 0; g_options[num_options].long_option != NULL; ++num_options)
@@ -468,9 +472,12 @@
         return error;
     }
 
-    long_options = (struct option *) malloc ((num_options + 1) * sizeof (struct option));
+    BuildGetOptTable (g_options, long_options_vector, num_options);
 
-    BuildGetOptTable (g_options, &long_options, num_options);
+    if (long_options_vector.empty())
+        long_options = NULL;
+    else
+        long_options = &long_options_vector.front();
 
     if (long_options == NULL)
     {
@@ -625,7 +632,9 @@
                 error.SetErrorStringWithFormat ("invalid option with value %i", val);
             }
             if (error.Fail())
+            {
                 return error;
+            }
         }
     }
     





More information about the lldb-commits mailing list