Fixed a couple of memory leaks and an incorrect index bounds check.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8635 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
ejakowatz
2004-08-24 23:54:02 +00:00
parent 968aa8c895
commit 72a804515c
3 changed files with 39 additions and 17 deletions
+3
View File
@@ -125,6 +125,8 @@ status_t BMessageBody::AddData(const char *name, const T1 &data, type_code type)
status_t err = B_OK;
BMessageField* BMF = FindData(name, type, err);
if (err)
{
if (err == B_NAME_NOT_FOUND)
{
// Reset err; we'll create the field
@@ -137,6 +139,7 @@ status_t BMessageBody::AddData(const char *name, const T1 &data, type_code type)
// type Y with the same name
return err;
}
}
if (!BMF)
{
+5 -3
View File
@@ -375,15 +375,17 @@ const void*
BMessageFieldImpl<T1, StoragePolicy, SizePolicy, PrintPolicy, FlattenPolicy, GetDataPolicy>::
DataAt(int32 index, ssize_t* size) const
{
if (index > CountItems())
return NULL;
if (index < CountItems())
{
*size = SizePolicy::Size(fData[index]);
const T1& ref = fData[index];
const T1* data = &ref;
return GetDataPolicy::GetData(data);//(const void*)data;
}
return NULL;
}
//------------------------------------------------------------------------------
template
<
+18 -1
View File
@@ -55,6 +55,7 @@ BMessageBody::BMessageBody(const BMessageBody &rhs)
//------------------------------------------------------------------------------
BMessageBody::~BMessageBody()
{
MakeEmpty();
}
//------------------------------------------------------------------------------
BMessageBody& BMessageBody::operator=(const BMessageBody &rhs)
@@ -294,11 +295,27 @@ status_t BMessageBody::RemoveData(const char* name, int32 index)
//------------------------------------------------------------------------------
status_t BMessageBody::RemoveName(const char* name)
{
return fData.erase(name) ? B_OK : B_NAME_NOT_FOUND;
TMsgDataMap::iterator i = fData.find(name);
if (i == fData.end())
{
return B_NAME_NOT_FOUND;
}
delete i->second;
fData.erase(i);
return B_OK;
}
//------------------------------------------------------------------------------
status_t BMessageBody::MakeEmpty()
{
for (TMsgDataMap::iterator i = fData.begin();
i != fData.end();
++i)
{
delete i->second;
}
fData.clear();
return B_OK;
}