Skip to content

Commit

Permalink
Fixed|libdoomsday|Thinker: Crash at shutdown after zapping a thinker
Browse files Browse the repository at this point in the history
Zapping should retain the malloc flag of a thinker so that it can
be later freed using the appropriate function.
  • Loading branch information
skyjake committed Aug 16, 2014
1 parent 692bae0 commit 554da99
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
6 changes: 3 additions & 3 deletions doomsday/libdoomsday/include/doomsday/world/thinker.h
Expand Up @@ -268,9 +268,9 @@ template <typename Type>
class ThinkerT : public Thinker
{
public:
ThinkerT() : Thinker(sizeof(Type)) {}
ThinkerT(de::dsize sizeInBytes,
AllocMethod alloc = AllocateStandard)
ThinkerT(AllocMethod alloc = AllocateStandard)
: Thinker(alloc, sizeof(Type)) {}
ThinkerT(de::dsize sizeInBytes, AllocMethod alloc = AllocateStandard)
: Thinker(alloc, sizeInBytes) {}
ThinkerT(Type const &thinker,
de::dsize sizeInBytes = sizeof(Type),
Expand Down
11 changes: 9 additions & 2 deletions doomsday/libdoomsday/src/world/thinker.cpp
Expand Up @@ -100,6 +100,13 @@ DENG2_PIMPL_NOREF(Thinker)
data = 0;
size = 0;
}

static void clearBaseToZero(thinker_s *base, dsize size)
{
bool const stdAlloc = CPP_BOOL(base->_flags & THINKF_STD_MALLOC);
memset(base, 0, size);
if(stdAlloc) base->_flags |= THINKF_STD_MALLOC;
}
};

#define STRUCT_MEMBER_ACCESSORS() \
Expand Down Expand Up @@ -167,7 +174,7 @@ void Thinker::zap()
delete d->data;
d->data = 0;

memset(d->base, 0, d->size);
Instance::clearBaseToZero(d->base, d->size);
}

bool Thinker::isDisabled() const
Expand Down Expand Up @@ -250,7 +257,7 @@ void Thinker::release(thinker_s &thinkerBase)
void Thinker::zap(thinker_s &thinkerBase, dsize sizeInBytes)
{
delete reinterpret_cast<IData *>(thinkerBase.d);
memset(&thinkerBase, 0, sizeInBytes);
Instance::clearBaseToZero(&thinkerBase, sizeInBytes);
}

void Thinker::setData(Thinker::IData *data)
Expand Down

0 comments on commit 554da99

Please sign in to comment.