[Lldb-commits] [lldb] r201206 - Avoid leaking namebuf in case of an early exit
Enrico Granata
egranata at apple.com
Tue Feb 11 19:37:33 PST 2014
Author: enrico
Date: Tue Feb 11 21:37:33 2014
New Revision: 201206
URL: http://llvm.org/viewvc/llvm-project?rev=201206&view=rev
Log:
Avoid leaking namebuf in case of an early exit
Modified:
lldb/trunk/source/Host/common/Host.cpp
Modified: lldb/trunk/source/Host/common/Host.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/Host.cpp?rev=201206&r1=201205&r2=201206&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/Host.cpp (original)
+++ lldb/trunk/source/Host/common/Host.cpp Tue Feb 11 21:37:33 2014
@@ -777,8 +777,8 @@ bool
Host::SetShortThreadName (lldb::pid_t pid, lldb::tid_t tid,
const char *thread_name, size_t len)
{
- char *namebuf = (char *)::malloc (len + 1);
-
+ std::unique_ptr<char[]> namebuf(new char[len+1]);
+
// Thread names are coming in like '<lldb.comm.debugger.edit>' and
// '<lldb.comm.debugger.editline>'. So just chopping the end of the string
// off leads to a lot of similar named threads. Go through the thread name
@@ -787,10 +787,10 @@ Host::SetShortThreadName (lldb::pid_t pi
if (lastdot && lastdot != thread_name)
thread_name = lastdot + 1;
- ::strncpy (namebuf, thread_name, len);
+ ::strncpy (namebuf.get(), thread_name, len);
namebuf[len] = 0;
- int namebuflen = strlen(namebuf);
+ int namebuflen = strlen(namebuf.get());
if (namebuflen > 0)
{
if (namebuf[namebuflen - 1] == '(' || namebuf[namebuflen - 1] == '>')
@@ -799,10 +799,8 @@ Host::SetShortThreadName (lldb::pid_t pi
namebuflen--;
namebuf[namebuflen] = 0;
}
- return Host::SetThreadName (pid, tid, namebuf);
+ return Host::SetThreadName (pid, tid, namebuf.get());
}
-
- ::free(namebuf);
return false;
}
More information about the lldb-commits
mailing list