mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
BUG: potential memory leaks in HashPtrTable::set (#1787)
- backported fix from develop COMP: incorrect variable names in PtrListOpsTemplates.C
This commit is contained in:
@ -5,7 +5,7 @@
|
|||||||
\\ / A nd | www.openfoam.com
|
\\ / A nd | www.openfoam.com
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2018 OpenCFD Ltd.
|
Copyright (C) 2018-2020 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -86,7 +86,19 @@ inline bool Foam::HashPtrTable<T, Key, Hash>::set
|
|||||||
T* ptr
|
T* ptr
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return this->parent_type::set(key, ptr);
|
// Newer: const T* old = this->get(key);
|
||||||
|
|
||||||
|
iterator iter(this->find(key));
|
||||||
|
const T* old = (iter.good() ? iter.val() : nullptr);
|
||||||
|
|
||||||
|
const bool ok = this->parent_type::set(key, ptr);
|
||||||
|
|
||||||
|
if (ok && old != ptr)
|
||||||
|
{
|
||||||
|
delete const_cast<T*>(old);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
\\ / A nd | www.openfoam.com
|
\\ / A nd | www.openfoam.com
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2019 OpenCFD Ltd.
|
Copyright (C) 2019-2020 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -79,7 +79,7 @@ void Foam::sortedOrder
|
|||||||
template<class T>
|
template<class T>
|
||||||
void Foam::sort(UPtrList<T>& list)
|
void Foam::sort(UPtrList<T>& list)
|
||||||
{
|
{
|
||||||
labelList order(input.size());
|
labelList order(list.size());
|
||||||
sortedOrder(list, order);
|
sortedOrder(list, order);
|
||||||
list.sortOrder(order, false); // false = allow nullptr
|
list.sortOrder(order, false); // false = allow nullptr
|
||||||
}
|
}
|
||||||
@ -88,7 +88,7 @@ void Foam::sort(UPtrList<T>& list)
|
|||||||
template<class T, class Compare>
|
template<class T, class Compare>
|
||||||
void Foam::sort(UPtrList<T>& list, const Compare& comp)
|
void Foam::sort(UPtrList<T>& list, const Compare& comp)
|
||||||
{
|
{
|
||||||
labelList order(input.size());
|
labelList order(list.size());
|
||||||
sortedOrder(list, order, comp);
|
sortedOrder(list, order, comp);
|
||||||
list.sortOrder(order, false); // false = allow nullptr
|
list.sortOrder(order, false); // false = allow nullptr
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user