Don’t leak memory when reading memory and we do an early return for error conditions.

llvm-svn: 201164
This commit is contained in:
Greg Clayton 2014-02-11 17:49:50 +00:00
parent 539997978e
commit f075824998
1 changed files with 3 additions and 4 deletions

View File

@ -2476,12 +2476,12 @@ RNBRemote::HandlePacket_m (const char *p)
return SendPacket ("");
}
uint8_t *buf = (uint8_t *)malloc (length);
if (buf == NULL)
std::string buf(length, '\0');
if (buf.empty())
{
return SendPacket ("E78");
}
int bytes_read = DNBProcessMemoryRead (m_ctx.ProcessID(), addr, length, buf);
int bytes_read = DNBProcessMemoryRead (m_ctx.ProcessID(), addr, buf.size(), &buf[0]);
if (bytes_read == 0)
{
return SendPacket ("E08");
@ -2494,7 +2494,6 @@ RNBRemote::HandlePacket_m (const char *p)
std::ostringstream ostrm;
for (int i = 0; i < length; i++)
ostrm << RAWHEX8(buf[i]);
free (buf);
return SendPacket (ostrm.str ());
}