[Lldb-commits] [lldb] r157519 - in /lldb/trunk: include/lldb/Core/StringList.h source/Core/StringList.cpp source/Interpreter/CommandObject.cpp

Greg Clayton gclayton at apple.com
Sat May 26 10:21:15 PDT 2012


Author: gclayton
Date: Sat May 26 12:21:14 2012
New Revision: 157519

URL: http://llvm.org/viewvc/llvm-project?rev=157519&view=rev
Log:
Fixed memory management issues introduced by revision 157507. 

A local std::string was being filled in and then the function would return "s.c_str()".
A local StreamString (which contains a std::string) was being filled in, and essentially also returning the c string from the std::string, though it was in a the StreamString class.

The fix was to not do this by passing a stream object into StringList::Join() and fix the "arch_helper()" function to do what it should: cache the result in a global.


Modified:
    lldb/trunk/include/lldb/Core/StringList.h
    lldb/trunk/source/Core/StringList.cpp
    lldb/trunk/source/Interpreter/CommandObject.cpp

Modified: lldb/trunk/include/lldb/Core/StringList.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/StringList.h?rev=157519&r1=157518&r2=157519&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/StringList.h (original)
+++ lldb/trunk/include/lldb/Core/StringList.h Sat May 26 12:21:14 2012
@@ -51,8 +51,8 @@
     const char *
     GetStringAtIndex (size_t idx) const;
 
-    const char *
-    Join (const char *seperator);
+    void
+    Join (const char *separator, Stream &strm);
 
     void
     Clear ();

Modified: lldb/trunk/source/Core/StringList.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/StringList.cpp?rev=157519&r1=157518&r2=157519&view=diff
==============================================================================
--- lldb/trunk/source/Core/StringList.cpp (original)
+++ lldb/trunk/source/Core/StringList.cpp Sat May 26 12:21:14 2012
@@ -95,23 +95,20 @@
     return NULL;
 }
 
-const char *
-StringList::Join (const char *separator)
+void
+StringList::Join (const char *separator, Stream &strm)
 {
     uint32_t size = GetSize();
+    
     if (size == 0)
-        return "";
-    if (size == 1)
-        return GetStringAtIndex(0);
-
-    std::string buf;
+        return;
+    
     for (uint32_t i = 0; i < size; ++i)
     {
         if (i > 0)
-            buf.append(separator);
-        buf.append(GetStringAtIndex(i));
+            strm.PutCString(separator);
+        strm.PutCString(GetStringAtIndex(i));
     }
-    return buf.c_str();;
 }
 
 void

Modified: lldb/trunk/source/Interpreter/CommandObject.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandObject.cpp?rev=157519&r1=157518&r2=157519&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CommandObject.cpp (original)
+++ lldb/trunk/source/Interpreter/CommandObject.cpp Sat May 26 12:21:14 2012
@@ -849,12 +849,15 @@
 static
 const char *arch_helper()
 {
-    StringList archs;
-    ArchSpec::AutoComplete(NULL, archs);
-    StreamString ss;
-    ss.Printf("These are the supported architecture names:\n");
-    ss.Printf("%s\n", archs.Join("\n"));
-    return ss.GetData();
+    static StreamString g_archs_help;
+    if (g_archs_help.GetData() == NULL)
+    {
+        StringList archs;
+        ArchSpec::AutoComplete(NULL, archs);
+        g_archs_help.Printf("These are the supported architecture names:\n");
+        archs.Join("%s\n", g_archs_help);
+    }
+    return g_archs_help.GetData();
 }
 
 CommandObject::ArgumentTableEntry





More information about the lldb-commits mailing list