Skip to content

Commit

Permalink
Client|libcore: Avoid a crash during shutdown
Browse files Browse the repository at this point in the history
Don't bother deleting recycled memory during an abnormal shutdown.
  • Loading branch information
skyjake committed Aug 26, 2017
1 parent 276da7a commit 91b102c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions doomsday/apps/client/src/dd_main.cpp
Expand Up @@ -45,6 +45,7 @@
#include <de/timer.h>
#include <de/ArrayValue>
#include <de/CommandLine>
#include <de/Garbage>
#include <de/NativeFile>
#include <de/PackageLoader>
#include <de/LinkFile>
Expand Down Expand Up @@ -601,6 +602,8 @@ void App_AbnormalShutdown(char const *message)
//Sys_Shutdown();
DD_Shutdown();

Garbage_ForgetAndLeak(); // At this point, it's too late.

// Get outta here.
exit(1);
}
Expand Down
7 changes: 7 additions & 0 deletions doomsday/sdk/libcore/include/de/core/garbage.h
Expand Up @@ -87,6 +87,13 @@ DENG2_PUBLIC void Garbage_RemoveIfTrashed(void *ptr);
*/
DENG2_PUBLIC void Garbage_Recycle(void);

/**
* Clears the garbage contents without actually freeing any memory. This
* should only be called under exceptional circumstances to quickly dismiss
* all recycled memory. Everything in the trash will leak!
*/
DENG2_PUBLIC void Garbage_ForgetAndLeak(void);

/**
* Frees all pointers in every thread's garbage if they are using a specific
* destructor function.
Expand Down
20 changes: 20 additions & 0 deletions doomsday/sdk/libcore/src/core/garbage.cpp
Expand Up @@ -79,6 +79,11 @@ struct Garbage : public Lockable
allocs.clear();
}
}

void forgetAndLeak()
{
allocs.clear(); // Oh well...
}
};

struct Garbages : public std::map<QThread *, Garbage *>, public Lockable
Expand Down Expand Up @@ -109,6 +114,16 @@ struct Garbages : public std::map<QThread *, Garbage *>, public Lockable
i->second->recycle(func);
}
}

void forgetAndLeak()
{
DENG2_GUARD(this);
for (iterator i = begin(); i != end(); ++i)
{
i->second->forgetAndLeak();
}
clear();
}
};

} // namespace internal
Expand Down Expand Up @@ -193,6 +208,11 @@ void Garbage_Recycle(void)
g->recycle();
}

void Garbage_ForgetAndLeak(void)
{
garbages.forgetAndLeak();
}

void Garbage_RecycleAllWithDestructor(GarbageDestructor destructor)
{
garbages.recycleWithDestructor(destructor);
Expand Down

0 comments on commit 91b102c

Please sign in to comment.