Fix memory leaks in IdList::{MoveSelfInto,DeepCopyInto}.

Note that this requires IdLists to be zero-initialized
to work correctly.
This commit is contained in:
whitequark 2015-11-06 12:41:56 +03:00
parent 45f056c852
commit 97fa6355cc

View File

@ -348,12 +348,14 @@ public:
} }
void MoveSelfInto(IdList<T,H> *l) { void MoveSelfInto(IdList<T,H> *l) {
l->Clear();
memcpy(l, this, sizeof(*this)); memcpy(l, this, sizeof(*this));
elemsAllocated = n = 0; elemsAllocated = n = 0;
elem = NULL; elem = NULL;
} }
void DeepCopyInto(IdList<T,H> *l) { void DeepCopyInto(IdList<T,H> *l) {
l->Clear();
l->elem = (T *)MemAlloc(elemsAllocated * sizeof(elem[0])); l->elem = (T *)MemAlloc(elemsAllocated * sizeof(elem[0]));
memcpy(l->elem, elem, elemsAllocated * sizeof(elem[0])); memcpy(l->elem, elem, elemsAllocated * sizeof(elem[0]));
l->elemsAllocated = elemsAllocated; l->elemsAllocated = elemsAllocated;