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

View File

@ -125,17 +125,20 @@ 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 == B_NAME_NOT_FOUND)
if (err)
{
// Reset err; we'll create the field
err = B_OK;
}
else
{
// Looking for B_BAD_TYPE here in particular, which would indicate
// that we tried to add data of type X when we already had data of
// type Y with the same name
return err;
if (err == B_NAME_NOT_FOUND)
{
// Reset err; we'll create the field
err = B_OK;
}
else
{
// Looking for B_BAD_TYPE here in particular, which would indicate
// that we tried to add data of type X when we already had data of
// type Y with the same name
return err;
}
}
if (!BMF)

View File

@ -375,14 +375,16 @@ 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;
*size = SizePolicy::Size(fData[index]);
const T1& ref = fData[index];
const T1* data = &ref;
return GetDataPolicy::GetData(data);//(const void*)data;
}
return GetDataPolicy::GetData(data);//(const void*)data;
return NULL;
}
//------------------------------------------------------------------------------
template

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;
}