Tracker: fix memory leak, CID 600996

We now only create the BString if we're going to put it in the list.
This commit is contained in:
John Scipione 2014-07-22 19:11:51 -04:00
parent 10489e89dd
commit 9b9c1e2779

View File

@ -291,21 +291,19 @@ OffsetFrameOne(const char* DEBUG_ONLY(name), uint32, off_t, void* castToRect,
static void
AddMimeTypeString(BObjectList<BString> &list, Model* model)
AddMimeTypeString(BObjectList<BString>& list, Model* model)
{
BString* mimeType = new BString(model->MimeType());
if (mimeType->Length()) {
const char* modelMimeType = model->MimeType();
if (modelMimeType != NULL && *modelMimeType != '\0') {
// only add the type if it's not already there
// ToDo: replace list with a hashmap
for (int32 i = list.CountItems(); i-- > 0;) {
BString* string = list.ItemAt(i);
if (string != NULL && !string->ICompare(*mimeType)) {
delete mimeType;
if (string != NULL && string->ICompare(modelMimeType) == 0)
return;
}
}
list.AddItem(mimeType);
list.AddItem(new BString(modelMimeType));
}
}