Fixed potential memory leak. If user tried to add data of type X when we already had data of type Y with the same name, a new BMessageField of type Y would be created and added to the field map, leaving the old type X field orphaned.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8613 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -125,8 +125,18 @@ status_t BMessageBody::AddData(const char *name, const T1 &data, type_code type)
|
||||
status_t err = B_OK;
|
||||
BMessageField* BMF = FindData(name, type, err);
|
||||
|
||||
// Reset err; we just want the variable
|
||||
err = B_OK;
|
||||
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)
|
||||
{
|
||||
@@ -142,7 +152,7 @@ status_t BMessageBody::AddData(const char *name, const T1 &data, type_code type)
|
||||
}
|
||||
|
||||
if (!err)
|
||||
{
|
||||
{
|
||||
BMessageFieldImpl<T1>* RItem =
|
||||
dynamic_cast<BMessageFieldImpl<T1>*>(BMF);
|
||||
if (!RItem)
|
||||
|
||||
Reference in New Issue
Block a user